[英]C# string to Inno Setup
我有一个C#DLL,其中公开了一种生成字符串的方法。
我想从Inno Setup调用此方法,然后接收字符串。
function GetInformationEx():String;
external 'GetInformationEx@{src}\data\tools\ZipLib.dll stdcall loadwithalteredsearchpath';
procedure ShowProgress(progress:Integer);
var
information : String;
begin
WriteDebugString('ShowProgress called');
if(progress > pbStateZip.position) then
begin
pbStateZip.position := progress;
lblState2.Caption := IntToStr(progress)+' %';
try
information := GetInformationEx();
except
ShowExceptionMessage;
end;
//Do something with the information
end
if(progress >= 100)then
begin
KillTimer(0,m_timer_ID);
//Inform that the extraction is done
end
WriteDebugString('ShowProgress leave');
end;
这是我简单的C#部分
[DllExport("GetInformationEx", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static String GetInformationEx()
{
return "Some simple text message || or heavy information";
}
我的问题是:
我必须将哪种类型的信息发送回Inno Setup,以便Inno Setup可以正确处理它?
到目前为止,我收到此消息
PS:我读了这篇文章:
从C#DLL中使用非托管导出返回字符串到Inno Setup脚本
但是我希望C#代码负责该字符串。
.NET String
类型绝对不会编组为Pascal string
类型。 .NET对Pascal类型一无所知。
.NET可以将字符串封送至字符数组(而Pascal可以封送来自字符数组的字符串)。 但是,当字符串是函数的返回类型时,就存在为字符串分配内存的问题(谁分配内存,谁释放内存)。
这就是为什么您所指出的解决方案建议您使用ref / out参数的原因,因为调用者可以通过这种方式提供一个缓冲区,.NET可以将字符串编组到该缓冲区。 因此分配没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.