简体   繁体   中英

Why Inno Setup can not load the proc?

I need to call custom dll function in CurStepChanged where CurStep = ssInstall .

[Files]
Source: "publish\InnoSetupHelper.dll"; Flags: dontcopy

[Code]
function StopService(ServiceName: String; TimeOut: Integer): Integer;
external 'StopService@InnoSetupHelper.dll cdecl delayload loadwithalteredsearchpath'; 

procedure CurStepChanged(CurStep: TSetupStep);
var
ErrorCode: Integer;
begin
  case CurStep of
    ssInstall: begin
      ErrorCode := StopService('XxxService', 10000); // line 179
      if ErrorCode <> 0 then
        MsgBox(FmtMessage('Stop service failed: %1', [ErrorCode]), mbCriticalError, MB_OK);
    end;
  end;
end;
EXTERN_C_START

__declspec(dllexport) DWORD StopService(PCWSTR serviceName, DWORD waitStopTimeoutMilliseconds);

EXTERN_C_END

I tried delayload only, loadwithalteredsearchpath only, no delayload and loadwithalteredsearchpath , all not work, either:

在此处输入图像描述

or:

在此处输入图像描述

  1. Your DLL must be 32-bit. Your project has 64-bit target.
  2. You should not link against Runtime DLL (or when you do, you have to distribute the Runtime DLL along). I suggest you link the Runtime statically. In project Properties , go to C/C++ > Code Generation > Runtime Library and select Multi-threaded (not DLL ).
  3. You are missing files: prefix in your external declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM