Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 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

По моему мнению все типы соответствуют запрашиваемым, потому и не понимаю в чем здесь ошибка.

Приложение:
  1.  
  2.  
  3. uses
  4. Forms,Windows,WinSvc,Dialogs;
  5.  
  6. type
  7. SC_HANDLE = Cardinal;
  8. SC_STATUS_TYPE=(SC_STATUS_PROCESS_INFO);
  9. SERVICE_STATUS_PROCESS = record
  10. dwServiceType :DWORD;
  11. dwCurrentState :DWORD;
  12. dwControlsAccepted :DWORD;
  13. dwWin32ExitCode :DWORD;
  14. dwServiceSpecificExitCode: DWORD;
  15. dwCheckPoint: DWORD;
  16. dwWaitHint: DWORD;
  17. dwProcessId: DWORD;
  18. dwServiceFlags: DWORD;
  19. end;
  20.  
  21. var
  22. gSvcStatus : SERVICE_STATUS;
  23. gSvcStatusHandle : SERVICE_STATUS_HANDLE;
  24. ghSvcStopEvent : THANDLE =0;
  25. DispatchTable:array[0..3] of _SERVICE_TABLE_ENTRYA;
  26. schSCManager: SC_HANDLE;
  27. schService: SC_HANDLE;
  28.  
  29.  
  30. Procedure DoStartSvc(); STDCALL;
  31. var
  32.  
  33. dwOldCheckPoint :DWORD;
  34. dwStartTickCount :DWORD;
  35. dwWaitTime :DWORD;
  36. dwBytesNeeded :DWORD;
  37. ssStatus : SERVICE_STATUS_PROCESS;
  38. Begin
  39.  
  40.  
  41. // Get a handle to the SCM database.
  42. schSCManager:= OpenSCManager(
  43. nil, // local computer
  44. nil, // servicesActive database
  45. SC_MANAGER_ALL_ACCESS); // full access rights
  46.  
  47. if schSCManager=0 then
  48. ShowMessage('OpenSCManager failed');
  49.  
  50. // Get a handle to the service.
  51. schService:= OpenService(
  52. schSCManager, // SCM database
  53. PCHAR('Player1'), // name of service
  54. SERVICE_ALL_ACCESS); // full access
  55.  
  56. if schService=0 then
  57. Begin
  58. ShowMessage('OpenService failed');
  59. CloseServiceHandle(schSCManager);
  60. End;
  61.  
  62. // Check the status in case the service is not stopped.
  63. if QueryServiceStatusEx(
  64. schService, // handle to service
  65. SC_STATUS_PROCESS_INFO, // information level
  66. @ssStatus, // address of structure
  67. sizeof(SERVICE_STATUS_PROCESS), // size of structure
  68. dwBytesNeeded )=false // size needed if buffer is too
  69.  
  70. small
  71. then
  72. Begin
  73. ShowMessage('QueryServiceStatusEx failed');
  74. CloseServiceHandle(schService);
  75. CloseServiceHandle(schSCManager);
  76. End;
  77.  
  78. // Check if the service is already running. It would be possible
  79. // to stop the service here, but for simplicity this example just returns.
  80. if not(ssStatus.dwCurrentState=SERVICE_STOPPED) and
  81.  
  82. not(ssStatus.dwCurrentState = SERVICE_STOP_PENDING)
  83. Then
  84. Begin
  85. ShowMessage('Cannot start the service because it is already running');
  86. CloseServiceHandle(schService);
  87. CloseServiceHandle(schSCManager);
  88. End;
  89.  
  90. // Save the tick count and initial checkpoint.
  91. dwStartTickCount:= GetTickCount();
  92. dwOldCheckPoint:= ssStatus.dwCheckPoint;
  93.  
  94. // Wait for the service to stop before attempting to start it.
  95. while ssStatus.dwCurrentState = SERVICE_STOP_PENDING do
  96. Begin
  97. // Do not wait longer than the wait hint. A good interval is
  98. // one-tenth of the wait hint but not less than 1 second
  99. // and not more than 10 seconds.
  100.  
  101. dwWaitTime:=ssStatus.dwWaitHint mod 10;
  102.  
  103. if dwWaitTime < 1000 then
  104. dwWaitTime:= 1000
  105. else
  106. if dwWaitTime > 10000 then
  107. dwWaitTime:= 10000;
  108.  
  109. Sleep( dwWaitTime );
  110.  
  111. // Check the status until the service is no longer stop pending.
  112.  
  113. if QueryServiceStatusEx(
  114. schService, // handle to service
  115. SC_STATUS_PROCESS_INFO, // information level
  116. @ssStatus, // address of structure
  117. sizeof(SERVICE_STATUS_PROCESS), // size of structure
  118. dwBytesNeeded )=false // size needed if buffer is
  119.  
  120. too small
  121. then
  122. Begin
  123. ShowMessage('QueryServiceStatusEx failed');
  124. CloseServiceHandle(schService);
  125. CloseServiceHandle(schSCManager);
  126. End;
  127.  
  128. if ssStatus.dwCheckPoint > dwOldCheckPoint
  129. then
  130. Begin
  131. // Continue to wait and check.
  132. dwStartTickCount:= GetTickCount();
  133. dwOldCheckPoint:= ssStatus.dwCheckPoint;
  134. End
  135. else
  136. if (GetTickCount()-dwStartTickCount) > ssStatus.dwWaitHint
  137. then
  138. Begin
  139. ShowMessage('Timeout waiting for service to stop');
  140. CloseServiceHandle(schService);
  141. CloseServiceHandle(schSCManager);
  142. End;
  143. End;
  144.  
  145. // Attempt to start the service.
  146.  
  147. if StartService(
  148. schService, // handle to service
  149. 0, // number of arguments
  150. nil)=false // no arguments
  151. then
  152. Begin
  153. ShowMessage('StartService failed');
  154. CloseServiceHandle(schService);
  155. CloseServiceHandle(schSCManager);
  156. end
  157. else
  158. ShowMessage('Service start pending');
  159.  
  160. // Check the status until the service is no longer start pending.
  161.  
  162. if QueryServiceStatusEx(
  163. schService, // handle to service
  164. SC_STATUS_PROCESS_INFO, // info level
  165. @ssStatus, // address of structure
  166. sizeof(SERVICE_STATUS_PROCESS), // size of structure
  167. dwBytesNeeded )=false // if buffer too small
  168. then
  169. Begin
  170. ShowMessage('QueryServiceStatusEx failed');
  171. CloseServiceHandle(schService);
  172. CloseServiceHandle(schSCManager);
  173. End;
  174.  
  175. // Save the tick count and initial checkpoint.
  176.  
  177. dwStartTickCount:= GetTickCount();
  178. dwOldCheckPoint:= ssStatus.dwCheckPoint;
  179.  
  180. while ssStatus.dwCurrentState = SERVICE_START_PENDING do
  181. Begin
  182. // Do not wait longer than the wait hint. A good interval is
  183. // one-tenth the wait hint, but no less than 1 second and no
  184. // more than 10 seconds.
  185.  
  186. dwWaitTime:= ssStatus.dwWaitHint mod 10;
  187.  
  188. if dwWaitTime < 1000
  189. then
  190. dwWaitTime:= 1000
  191. else
  192. if dwWaitTime > 10000
  193. then
  194. dwWaitTime:= 10000;
  195.  
  196. Sleep( dwWaitTime );
  197.  
  198. // Check the status again.
  199.  
  200. if QueryServiceStatusEx(
  201. schService, // handle to service
  202. SC_STATUS_PROCESS_INFO, // info level
  203. @ssStatus, // address of structure
  204. sizeof(SERVICE_STATUS_PROCESS), // size of structure
  205. dwBytesNeeded )=false // if buffer too small
  206. then
  207. begin
  208. ShowMessage('QueryServiceStatusEx failed');
  209. break;
  210. End;
  211.  
  212. if ssStatus.dwCheckPoint > dwOldCheckPoint
  213. Then
  214. Begin
  215. // Continue to wait and check.
  216.  
  217. dwStartTickCount:= GetTickCount();
  218. dwOldCheckPoint:= ssStatus.dwCheckPoint;
  219. End
  220. else
  221. Begin
  222. if(GetTickCount()-dwStartTickCount) > ssStatus.dwWaitHint
  223. // No progress made within the wait hint.
  224. then
  225. break;
  226. End;
  227. End;
  228.  
  229. // Determine whether the service is running.
  230. if ssStatus.dwCurrentState = SERVICE_RUNNING
  231. then
  232. ShowMessage('Service started successfully')
  233. else
  234. ShowMessage('Service not started');
  235. CloseServiceHandle(schService);
  236. CloseServiceHandle(schSCManager);
  237. End;


SOA Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: 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

Комментарий к оценке: Спасибо

Мини-форум вопроса

Мини-форум пуст.

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 11:35
Выполнено за 0.03 сек.