Can anyone tell me why the following piece of code gives an error of undeclared identifier for the SC_HANDLE declarations?
Code:
unsigned char StartPortTalkDriver(void)
{
SC_HANDLE SchSCManager;
SC_HANDLE schService;
BOOL ret;
DWORD err;
/* Open Handle to Service Control Manager */
SchSCManager = OpenSCManager (NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
SC_MANAGER_ALL_ACCESS); /* access required */
if (SchSCManager == NULL)
if (GetLastError() == ERROR_ACCESS_DENIED) {
/* We do not have enough rights to open the SCM, therefore we must */
/* be a poor user with only user rights. */
printf("PortTalk: You do not have rights to access the Service Control Manager and\n");
printf("PortTalk: the PortTalk driver is not installed or started. Please ask \n");
printf("PortTalk: your administrator to install the driver on your behalf.\n");
return(0);
}
do {
/* Open a Handle to the PortTalk Service Database */
schService = OpenService(SchSCManager, /* handle to service control manager database */
"PortTalk", /* pointer to name of service to start */
SERVICE_ALL_ACCESS); /* type of access to service */
if (schService == NULL)
switch (GetLastError()){
case ERROR_ACCESS_DENIED:
printf("PortTalk: You do not have rights to the PortTalk service database\n");
return(0);
case ERROR_INVALID_NAME:
printf("PortTalk: The specified service name is invalid.\n");
return(0);
case ERROR_SERVICE_DOES_NOT_EXIST:
printf("PortTalk: The PortTalk driver does not exist. Installing driver.\n");
printf("PortTalk: This can take up to 30 seconds on some machines . .\n");
InstallPortTalkDriver();
break;
}
} while (schService == NULL);
/* Start the PortTalk Driver. Errors will occur here if PortTalk.SYS file doesn't exist */
ret = StartService (schService, /* service identifier */
0, /* number of arguments */
NULL); /* pointer to arguments */
if (ret) printf("PortTalk: The PortTalk driver has been successfully started.\n");
else {
err = GetLastError();
if (err == ERROR_SERVICE_ALREADY_RUNNING)
printf("PortTalk: The PortTalk driver is already running.\n");
else {
printf("PortTalk: Unknown error while starting PortTalk driver service.\n");
printf("PortTalk: Does PortTalk.SYS exist in your \\System32\\Drivers Directory?\n");
return(0);
}
}
/* Close handle to Service Control Manager */
CloseServiceHandle (schService);
return(TRUE);
}
many thanks
Bazzz
Code tags added by Kermi3