C# 字符串到 Inno Setup

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:我读了这个post:
Returning a string from a C# DLL with Unmanaged Exports to Inno Setup script
但是我希望C#代码负责字符串。

.NET String 类型绝对不会编组为 Pascal string 类型。 .NET 对 Pascal 类型一无所知。

.NET 可以将字符串编组为字符数组(而 Pascal 可以从字符数组编组字符串)。但是当字符串是return类型的函数时,字符串的内存分配就会出现问题(谁分配内存,谁释放内存)。

这就是为什么 the solution in question you pointed to 建议您使用 ref/out 参数,因为这样调用者可以提供一个缓冲区,.NET 可以将字符串编组到其中。所以分配没有问题