|
Вопрос # 4 304/ вопрос открыт / |
|
Здравствуйте, эксперты!
Вопрос в следующем
Есть код, в котором возникает ошибка
Types of actual and formal parameters must be identical
Вот в этом месте
if StartService(
schService, // handle to service
0, // number of arguments
nil)=false // no arguments
then
По моему мнению все типы соответствуют запрашиваемым, потому и не понимаю в чем здесь ошибка.
Приложение: Переключить в обычный режим-
-
- uses
- Forms,Windows,WinSvc,Dialogs;
-
- type
- SC_HANDLE = Cardinal;
- SC_STATUS_TYPE=(SC_STATUS_PROCESS_INFO);
- SERVICE_STATUS_PROCESS = record
- dwServiceType :DWORD;
- dwCurrentState :DWORD;
- dwControlsAccepted :DWORD;
- dwWin32ExitCode :DWORD;
- dwServiceSpecificExitCode: DWORD;
- dwCheckPoint: DWORD;
- dwWaitHint: DWORD;
- dwProcessId: DWORD;
- dwServiceFlags: DWORD;
- end;
-
- var
- gSvcStatus : SERVICE_STATUS;
- gSvcStatusHandle : SERVICE_STATUS_HANDLE;
- ghSvcStopEvent : THANDLE =0;
- DispatchTable:array[0..3] of _SERVICE_TABLE_ENTRYA;
- schSCManager: SC_HANDLE;
- schService: SC_HANDLE;
-
-
- Procedure DoStartSvc(); STDCALL;
- var
-
- dwOldCheckPoint :DWORD;
- dwStartTickCount :DWORD;
- dwWaitTime :DWORD;
- dwBytesNeeded :DWORD;
- ssStatus : SERVICE_STATUS_PROCESS;
- Begin
-
-
- // Get a handle to the SCM database.
- schSCManager:= OpenSCManager(
- nil, // local computer
- nil, // servicesActive database
- SC_MANAGER_ALL_ACCESS); // full access rights
-
- if schSCManager=0 then
- ShowMessage('OpenSCManager failed');
-
- // Get a handle to the service.
- schService:= OpenService(
- schSCManager, // SCM database
- PCHAR('Player1'), // name of service
- SERVICE_ALL_ACCESS); // full access
-
- if schService=0 then
- Begin
- ShowMessage('OpenService failed');
- CloseServiceHandle(schSCManager);
- End;
-
- // Check the status in case the service is not stopped.
- if QueryServiceStatusEx(
- schService, // handle to service
- SC_STATUS_PROCESS_INFO, // information level
- @ssStatus, // address of structure
- sizeof(SERVICE_STATUS_PROCESS), // size of structure
- dwBytesNeeded )=false // size needed if buffer is too
-
- small
- then
- Begin
- ShowMessage('QueryServiceStatusEx failed');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
-
- // Check if the service is already running. It would be possible
- // to stop the service here, but for simplicity this example just returns.
- if not(ssStatus.dwCurrentState=SERVICE_STOPPED) and
-
- not(ssStatus.dwCurrentState = SERVICE_STOP_PENDING)
- Then
- Begin
- ShowMessage('Cannot start the service because it is already running');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
-
- // Save the tick count and initial checkpoint.
- dwStartTickCount:= GetTickCount();
- dwOldCheckPoint:= ssStatus.dwCheckPoint;
-
- // Wait for the service to stop before attempting to start it.
- while ssStatus.dwCurrentState = SERVICE_STOP_PENDING do
- Begin
- // Do not wait longer than the wait hint. A good interval is
- // one-tenth of the wait hint but not less than 1 second
- // and not more than 10 seconds.
-
- dwWaitTime:=ssStatus.dwWaitHint mod 10;
-
- if dwWaitTime < 1000 then
- dwWaitTime:= 1000
- else
- if dwWaitTime > 10000 then
- dwWaitTime:= 10000;
-
- Sleep( dwWaitTime );
-
- // Check the status until the service is no longer stop pending.
-
- if QueryServiceStatusEx(
- schService, // handle to service
- SC_STATUS_PROCESS_INFO, // information level
- @ssStatus, // address of structure
- sizeof(SERVICE_STATUS_PROCESS), // size of structure
- dwBytesNeeded )=false // size needed if buffer is
-
- too small
- then
- Begin
- ShowMessage('QueryServiceStatusEx failed');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
-
- if ssStatus.dwCheckPoint > dwOldCheckPoint
- then
- Begin
- // Continue to wait and check.
- dwStartTickCount:= GetTickCount();
- dwOldCheckPoint:= ssStatus.dwCheckPoint;
- End
- else
- if (GetTickCount()-dwStartTickCount) > ssStatus.dwWaitHint
- then
- Begin
- ShowMessage('Timeout waiting for service to stop');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
- End;
-
- // Attempt to start the service.
-
- if StartService(
- schService, // handle to service
- 0, // number of arguments
- nil)=false // no arguments
- then
- Begin
- ShowMessage('StartService failed');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- end
- else
- ShowMessage('Service start pending');
-
- // Check the status until the service is no longer start pending.
-
- if QueryServiceStatusEx(
- schService, // handle to service
- SC_STATUS_PROCESS_INFO, // info level
- @ssStatus, // address of structure
- sizeof(SERVICE_STATUS_PROCESS), // size of structure
- dwBytesNeeded )=false // if buffer too small
- then
- Begin
- ShowMessage('QueryServiceStatusEx failed');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
-
- // Save the tick count and initial checkpoint.
-
- dwStartTickCount:= GetTickCount();
- dwOldCheckPoint:= ssStatus.dwCheckPoint;
-
- while ssStatus.dwCurrentState = SERVICE_START_PENDING do
- Begin
- // Do not wait longer than the wait hint. A good interval is
- // one-tenth the wait hint, but no less than 1 second and no
- // more than 10 seconds.
-
- dwWaitTime:= ssStatus.dwWaitHint mod 10;
-
- if dwWaitTime < 1000
- then
- dwWaitTime:= 1000
- else
- if dwWaitTime > 10000
- then
- dwWaitTime:= 10000;
-
- Sleep( dwWaitTime );
-
- // Check the status again.
-
- if QueryServiceStatusEx(
- schService, // handle to service
- SC_STATUS_PROCESS_INFO, // info level
- @ssStatus, // address of structure
- sizeof(SERVICE_STATUS_PROCESS), // size of structure
- dwBytesNeeded )=false // if buffer too small
- then
- begin
- ShowMessage('QueryServiceStatusEx failed');
- break;
- End;
-
- if ssStatus.dwCheckPoint > dwOldCheckPoint
- Then
- Begin
- // Continue to wait and check.
-
- dwStartTickCount:= GetTickCount();
- dwOldCheckPoint:= ssStatus.dwCheckPoint;
- End
- else
- Begin
- if(GetTickCount()-dwStartTickCount) > ssStatus.dwWaitHint
- // No progress made within the wait hint.
- then
- break;
- End;
- End;
-
- // Determine whether the service is running.
- if ssStatus.dwCurrentState = SERVICE_RUNNING
- then
- ShowMessage('Service started successfully')
- else
- ShowMessage('Service not started');
- CloseServiceHandle(schService);
- CloseServiceHandle(schSCManager);
- End;
 |
Вопрос задал: SOA (статус: Посетитель)
Вопрос отправлен: 10 июня 2010, 09:42
Состояние вопроса: открыт, ответов: 1.
|
Ответ #1. Отвечает эксперт: min@y™
Ну всё правильно.
Заглянул бы в SDK:
BOOL StartService(
SC_HANDLE hService, // handle of service
DWORD dwNumServiceArgs, // number of arguments
LPCTSTR *lpServiceArgVectors // address of array of argument string pointers
);
...или в исходник модуля WinSvc.pas:
{$EXTERNALSYM StartService}
function StartService(hService: SC_HANDLE; dwNumServiceArgs: DWORD;
var lpServiceArgVectors: PChar): BOOL; stdcall;
Третий параметр передаётся как var (по ссылке), следовательно в него надо подставлять переменную PChar, но никак не константу.
И не надо было такую кучу кода вываливать.
 |
Ответ отправил: min@y™ (статус: Доктор наук)
Время отправки: 10 июня 2010, 10:10
Оценка за ответ: 5
Комментарий к оценке: Спасибо
|
Мини-форум вопроса
Мини-форум пуст.
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|