Runtime exception when calling dll function with parameter in Inno Setup

I successfully call the function in the DLL from Inno Setup, however when I return, I get a Runtime Error ... Exception: access violation at XXXXXXX. Record of address XXXXXX.

The function is declared as:

function CompleteInstall(szIntallPath: String) : Integer; external ' CompleteInstall@files :InstallHelper.dll stdcall setuponly'; 

And called:

 procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep = ssPostInstall then begin CompleteInstall('Parm1'); // ExpandConstant('{app}') end; end; 

No problem if I change the function so as not to accept the parameter. This still happens if I change it to accept a single integer parameter or declare it as a function and change the function as a void function with an integer parameter.

The called function does not return anything:

 __declspec(dllexport) int CompleteInstall(char* szInstallPath) { //AfxMessageBox ("Got here" /*szInstallPath*/, MB_OK); return 1; } 
+6
visual-c ++ inno-setup
source share
2 answers

You have a mismatch in the calling conventions. Or make the dll function use stdcall :

 __declspec(dllexport) __stdcall int CompleteInstall(char* szInstallPath) { //AfxMessageBox ("Got here" /*szInstallPath*/, MB_OK); return 1; } 

or change the function declaration to use cdecl instead of stdcall :

 function CompleteInstall(szIntallPath: String) : Integer; external ' CompleteInstall@files :InstallHelper.dll cdecl setuponly'; 
+9
source share

Although according to mghie (see comments) this should not matter in this case, you can use PChar instead of String , as this will be the more exact equivalent of the C char* declaration of char* .

String is a native Pascal type that is usually managed in a completely different way than PChar (although there seems to be not much in Inno PascalScript).

+2
source share

All Articles