SC_HANDLE

I am using MinGW and i get this errors:
loading.cpp: In function 'bool LoadDriver(const char*, const char*)':
loading.cpp:4:5: error: 'SC_HANDLE' was not declared in this scope
loading.cpp:4:15: error: expected ';' before 'hSCService'
loading.cpp:5:15: error: expected ';' before 'hSCManager'
loading.cpp:7:5: error: 'hSCManager' was not declared in this scope
loading.cpp:7:33: error: 'NULL' was not declared in this scope
loading.cpp:7:45: error: 'SC_MANAGER_ALL_ACCESS' was not declared in this scope
loading.cpp:7:67: error: 'OpenSCManager' was not declared in this scope
loading.cpp:11:5: error: 'hSCService' was not declared in this scope
loading.cpp:12:57: error: 'SERVICE_ALL_ACCESS' was not declared in this scope
loading.cpp:12:77: error: 'SERVICE_KERNEL_DRIVER' was not declared in this scope

loading.cpp:13:57: error: 'SERVICE_DEMAND_START' was not declared in this scope
loading.cpp:13:79: error: 'SERVICE_ERROR_NORMAL' was not declared in this scope
loading.cpp:14:100: error: 'CreateService' was not declared in this scope
loading.cpp:16:44: error: 'GetLastError' was not declared in this scope
loading.cpp:16:49: error: 'ERROR_SERVICE_EXISTS' was not declared in this scope
loading.cpp:17:80: error: 'OpenService' was not declared in this scope
loading.cpp:22:44: error: 'StartService' was not declared in this scope
loading.cpp:24:26: error: 'GetLastError' was not declared in this scope
loading.cpp:24:31: error: 'ERROR_SERVICE_ALREADY_RUNNING' was not declared in th
is scope
loading.cpp:28:36: error: 'CloseServiceHandle' was not declared in this scope

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
loading.cpp:32: confused by earlier errors, bailing out

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
bool LoadDriver( const char * cpDriverPath, const char * cpDriverName )
{
    SC_HANDLE hSCService;
    SC_HANDLE hSCManager;

    hSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
    if( hSCManager == NULL )
        return false;

    hSCService = CreateService( hSCManager, cpDriverName, cpDriverName,
                                                        SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
                                                        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
                                                        cpDriverPath, NULL, NULL, NULL, NULL, NULL );

    if( hSCService == NULL && GetLastError() == ERROR_SERVICE_EXISTS )
        hSCService = OpenService( hSCManager, cpDriverName, SERVICE_ALL_ACCESS );

    if( hSCService == NULL )
        return false;

    if( !StartService( hSCService, 0, NULL ) )
    {
        if( GetLastError() != ERROR_SERVICE_ALREADY_RUNNING )
                return false;
    }

    CloseServiceHandle( hSCManager );
    CloseServiceHandle( hSCService );

    return true;
}
Where is the problem?
These function are only available in windows xp or later, MinGW by default uses windows 95 settings (I think). So you need to define necessary macros yourself, like WINVER and WIN32_WINNT to 0x0501. Do this before including windows.h or any headers.
These function are only available in windows xp or later,
I'm sure I used them in NT 3.5.
This is the webpage for OpenSCManager on MSDN, it says:
Minimum supported client
Windows XP

Minimum supported server
Windows Server 2003

Header


Winsvc.h (include Windows.h)

Library


Advapi32.lib

DLL


Advapi32.dll

Unicode and ANSI names
OpenSCManagerW (Unicode) and OpenSCManagerA (ANSI)



http://msdn.microsoft.com/en-us/library/windows/desktop/ms684323%28v=vs.85%29.aspx


When did you use it in NT 3.5 ????
I started with NT in 1994 with Daytona Gold.
If "GetLastError()" and "NULL" weren't declared either I'm wondering if the OP even included Windows.h.
Topic archived. No new replies allowed.