Can';将字符串从inno传递到dll时,是否无法在dll函数中获取值?
我想将字符串传递给我的dll函数,但该函数无法获取值。 首先,我使用GetMyParam函数从cmd行获取字符串。是的,那么,我通过了 使用innotest函数将值添加到我的dllCan';将字符串从inno传递到dll时,是否无法在dll函数中获取值?,dll,inno-setup,param,Dll,Inno Setup,Param,我想将字符串传递给我的dll函数,但该函数无法获取值。 首先,我使用GetMyParam函数从cmd行获取字符串。是的,那么,我通过了 使用innotest函数将值添加到我的dll function innotest(PName:string):Integer; external 'innotest@E:\client\branch\maintain\1.4\bin\sdostate-debug\update.dll stdcall setuponly'; function GetMyPara
function innotest(PName:string):Integer;
external 'innotest@E:\client\branch\maintain\1.4\bin\sdostate-debug\update.dll stdcall setuponly';
function GetMyParam(PName:string):string;
var
CmdLine : String;
CmdLineLen : Integer;
i : Integer;
begin
Result := '';
CmdLineLen:=ParamCount();
for i:=0 to CmdLineLen do
begin
CmdLine:=ParamStr(i);
if CmdLine = PName then
begin
CmdLine:=ParamStr(i+1);
Result := CmdLine;
Exit;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
res: String;
begin
if (CurStep = ssPostInstall) and (Pos('setup', WizardSelectedTasks(false)) > 0)then
begin
res := GetMyParam('-myParam');
MsgBox(res, mbInformation, mb_Ok);
innotest(res);
end;
end;
Msgbox具有res值。
这是我的dll代码:字符串的长度是1
DWORD Update::innotest(string str)
{
LPCWSTR s = StringHelper::ANSIToUnicode(str).c_str();
MessageBox(0,s,0,0);
return 0;
}
您正在函数参数中使用
string
类型,这是内存中的字符序列,InnoSetup无法直接访问。您必须使用指向字符串类型的指针才能使其工作。因此,当您使用Unicode InnoSetup时,请按以下方式更改库函数参数,使其具有Unicode字符串指针类型。然后,您可以保持InnoSetup脚本的原样:
DWORD Update::innotest(LPCWSTR str)
{
MessageBox(0,s,0,0);
return 0;
}
您使用的是哪个版本的InnoSetup和ANSI或Unicode?如果是ANSI,这是不可能的。您必须使用Unicode版本的InnoSetup,因为您在库中使用LPCWSTR Unicode字符串,并且当您使用ANSI版本的InnoSetup时,字符串映射到ANSI字符串,并且没有Unicode字符串的类型。我已经实现了StringHelper,用于将ANSI字符串转换为Unicode。这样不行?对不起,我的错。你的函数有ANSI字符串作为参数(
str
是ANSI字符串),你有Unicode InnoSetup,对吗?如果是这样,那么在InnoSetup函数导入中将您的参数更改为PName:AnsiString
,您会没事的。我检查了我的InnoSetup是否为非Unicode。然后我下载了Unicode InnoSetup,并在我的dll模块中将(string str)更改为(wstring str)。在我的dll模块中,MessageBox返回乱码和运行时错误访问冲突,您能给我一些帮助吗?谢谢是 啊我已经按照你的建议解决了这个问题。感谢您的好意和耐心!实际上,使用string
作为参数可能是std::string
,这远不止是一个简单的字符序列,而且作为混合语言DLL函数参数完全不兼容。(顺便说一句,无论如何,您都不应该尝试通过值传递string
,即使在您自己的库中也是如此。)