Question

I am successfully calling a function in a DLL from Inno Setup, however upon returning I get a Runtime Error...Exception: Access violation at address XXXXXXX. Write 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;

There is no problem if I change the function to not take a parameter. It still occurs if I change it to take a single integer parameter or declare it as a function and change the function to be a void function with an integer parameter.

The called function does nothing but return:

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

Solution

You have a mismatch of the calling conventions. Either make the DLL function use stdcall as well:

__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';

OTHER TIPS

Although according to mghie (see comments) it shouldn't make a difference in this case, you might want to use PChar instead of String as that would be the more accurate equivalent of the C-declaration char*.

String is a Pascal-native type which is usually managed quite differently than a PChar (though apparently not so much in Inno's PascalScript).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top