I want to pass a string to my dll funcfion, but the function cannot get the value.
first I get the string from cmd line using GetMyParam function. it’s right.then, i pass
the value to my dll using innotest function.
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 has the res value.
here is my dll code: the string’s length is 1.
DWORD Update::innotest(string str)
{
LPCWSTR s = StringHelper::ANSIToUnicode(str).c_str();
MessageBox(0,s,0,0);
return 0;
}
You’re using
stringtype in your function parameter, what is a sequence of characters in memory, that InnoSetup cannot reach directly. You have to use pointer to string type to get it to work. So when you are using Unicode InnoSetup, change your library function parameter to have an Unicode string pointer type the following way. Then you can keep your InnoSetup script as it is: