Note that there are some explanatory texts on larger screens.

plurals
  1. POInno Setup Windows DLL function call with pointer to structure
    primarykey
    data
    text
    <p>I am trying to set a service's failure actions using Inno Setup's Pascal scripting language. I receive the classic <em>"access violation at address..."</em> error. Seems that it is impossible because the language don't have any support to pointers. Any ideas? Here is the code snippet:</p> <pre class="lang-pascal prettyprint-override"><code>type TScAction = record aType1 : Longword; Delay1 : Longword; aType2 : Longword; Delay2 : Longword; aType3 : Longword; Delay3 : Longword; end; type TServiceFailureActionsA = record dwResetPeriod : DWORD; pRebootMsg : String; pCommand : String; cActions : DWORD; saActions : TScAction; end; function ChangeServiceConfig2(hService: Longword; dwInfoLevel: Longword; lpInfo: TServiceFailureActionsA): BOOL; external 'ChangeServiceConfig2A@advapi32.dll stdcall'; procedure SimpleChangeServiceConfig(AService: string); var SCMHandle: Longword; ServiceHandle: Longword; sfActions: TServiceFailureActionsA; sActions: TScAction; begin try SCMHandle := OpenSCManager('', '', SC_MANAGER_ALL_ACCESS); if SCMHandle = 0 then RaiseException('SimpleChangeServiceConfig@OpenSCManager: ' + AService + ' ' + SysErrorMessage(DLLGetLastError)); try ServiceHandle := OpenService(SCMHandle, AService, SERVICE_ALL_ACCESS); if ServiceHandle = 0 then RaiseException('SimpleChangeServiceConfig@OpenService: ' + AService + ' ' + SysErrorMessage(DLLGetLastError)); try sActions.aType1 := SC_ACTION_RESTART; sActions.Delay1 := 60000; // First.nDelay: in milliseconds, MMC displayed in minutes sActions.aType2 := SC_ACTION_RESTART; sActions.Delay2 := 60000; sActions.aType3 := SC_ACTION_RESTART; sActions.Delay3 := 60000; sfActions.dwResetPeriod := 1; // in seconds, MMC displayes in days //sfActions.pRebootMsg := null; // reboot message unchanged //sfActions.pCommand := null; // command line unchanged sfActions.cActions := 3; // first, second and subsequent failures sfActions.saActions := sActions; if not ChangeServiceConfig2( ServiceHandle, // handle to service SERVICE_CONFIG_FAILURE_ACTIONS, // change: description sfActions) // new description then RaiseException('SimpleChangeServiceConfig@ChangeServiceConfig2: ' + AService + ' ' + SysErrorMessage(DLLGetLastError)); finally if ServiceHandle &lt;&gt; 0 then CloseServiceHandle(ServiceHandle); end; finally if SCMHandle &lt;&gt; 0 then CloseServiceHandle(SCMHandle); end; except ShowExceptionMessage; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload