Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime exception when calling dll function with parameter in Inno Setup

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;
}
like image 881
AlanKley Avatar asked Jun 05 '09 17:06

AlanKley


1 Answers

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';
like image 53
mghie Avatar answered Sep 20 '22 22:09

mghie