I am having a bit of a problem with the following declare:
The EBasic Windows.inc file declares this API as follows:
DECLARE IMPORT, _OpenSCManager ALIAS OpenSCManagerA(lpMachineName AS STRING,lpDatabaseName AS STRING,dwDesiredAccess AS INT),INT
I then try passing null strings as follows:
HSCMANAGER = _OpenSCManager(Chr$(0), Chr$(0), SC_MANAGER_ALL_ACCESS)
I've tried passing empty strings ("") but that's not the same thing and doesn't work anyways.
When I change the API as follows in the Windows.inc file as follows:
DECLARE IMPORT, _OpenSCManager ALIAS OpenSCManagerA(lpMachineName AS INT,lpDatabaseName AS INT,dwDesiredAccess AS INT),INT
And then call the function as follows:
HSCMANAGER = _OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS)
It works and I get back a handle.
Obviously my lack of knowledge of EBasic is showing. What is the proper way of passing a NULL pointer to string as an API parameter? I don't want to edit the windows.inc file since I must be using the API wrong.
In C++ this declare would be as follows:
SC_HANDLE WINAPI OpenSCManager(
__in_opt LPCTSTR lpMachineName,
__in_opt LPCTSTR lpDatabaseName,
__in DWORD dwDesiredAccess
);
which would be simplified as:
DWORD OpenSCManager(DWORD lpMachineName, DWORD lpDatabaseName, DWORD dwDesiredAccess);
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
BTW, for this API I pass NULL's for the first two parameters unless I want access the Service Control Manager on a different computer.
Okay, I saw another post on here with a similar problem. The DECLARES in the windows.inc file are off and should be as follows:
DECLARE IMPORT, CreateService ALIAS CreateServiceA(hSCManager AS UINT,lpServiceName AS POINTER,lpDisplayName AS POINTER,dwDesiredAccess AS INT,dwServiceType AS INT,dwStartType AS INT,dwErrorControl AS INT,lpBinaryPathName AS POINTER,lpLoadOrderGroup AS POINTER,lpdwTagId AS POINTER,lpDependencies AS POINTER,lp AS POINTER,lpPassword AS POINTER),INT
DECLARE IMPORT, OpenSCManager ALIAS OpenSCManagerA(lpMachineName AS POINTER,lpDatabaseName AS POINTER,dwDesiredAccess AS INT),INT
With the proper declares (as you noticed) you can pass a null string with the "".
That's because EB passes string by reference which means it uses the pointer internally.
Larry
Steven is correct, the delcares on many of the functions in windows.inc are wrong. It was converted from the VB4 declares as a convenience, I've been editing them as I find the wrong ones.
You pass a NULL with the word NULL by the way, not an empty string or CHR$(0) which is something completely different. And empty string "" still has an address. Windows API function generally require strings to be passed through a pointer as you have found so you can specify NULL for omitted parameters.
I tried NULL with the lpMachineName AS STRING format and the compiler complained. When I use NULL for the lpMachineName AS INT the compiler if fine with that.
My point was lpMachineName is a pointer, not a string as the declare is wrong.
When a parameter is declared as a pointer you can pass either a NULL or a string, as it expects.
the "lp" stands for "long pointer".
Paul.
Okay, I see what you mean. Thanks.
Thanks for clearing that up for me also.
Larry