在Inno Setup中使用参数调用dll函数时出现运行时异常 [英] Runtime exception when calling dll function with parameter in Inno Setup
问题描述
我已成功从Inno Setup调用DLL中的函数,但是返回时,我收到运行时错误...异常:地址XXXXXXX上的访问冲突.写地址XXXXXX.
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.
该函数声明为:
function CompleteInstall(szIntallPath: String) : Integer;
external 'CompleteInstall@files:InstallHelper.dll stdcall setuponly';
并称为:
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then begin
CompleteInstall('Parm1'); // ExpandConstant('{app}')
end;
end;
如果我将函数更改为不带参数,则没有问题.如果我将其更改为采用单个整数参数或将其声明为函数并将该函数更改为具有整数参数的void函数,则仍然会发生这种情况.
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;
}
推荐答案
您的调用约定不匹配.使DLL函数也使用stdcall
:
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;
}
或将函数声明更改为使用cdecl
而不是stdcall
:
or change the function declaration to use cdecl
instead of stdcall
:
function CompleteInstall(szIntallPath: String) : Integer;
external 'CompleteInstall@files:InstallHelper.dll cdecl setuponly';
这篇关于在Inno Setup中使用参数调用dll函数时出现运行时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!