从inno到dll传递字符串时,无法在dll函数中获取值?

时间:2012-09-12 08:43:57

标签: 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 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;
}

1 个答案:

答案 0 :(得分:2)

你在函数参数中使用string类型,内存中的字符序列是什么,InnoSetup无法直接到达。您必须使用指向字符串类型的指针才能使其工作。因此,当您使用Unicode InnoSetup时,请更改库函数参数以使用以下方式键入Unicode字符串指针。然后你可以保留你的InnoSetup脚本:

DWORD Update::innotest(LPCWSTR str)
{
    MessageBox(0,s,0,0);
    return 0;
}
相关问题