本文介绍了从具有非托管导出的C#DLL中返回一个字符串到Inno安装脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C#DLL,它使用类型,这是用于interop函数调用的数据类型。在C#方面,您可以使用 UnmanagedType.BStr
类型来编组您的字符串,而在Inno安装方面,您将使用 WideString
,它兼容类型。所以你的代码会改为这个(另见章节):
I would suggest you to use the BSTR
type, which is used to be a data type for interop function calls. On your C# side you'd marshall your string as the UnmanagedType.BStr
type and on the Inno Setup side you'd use the WideString
, which is compatible with the BSTR
type. So your code would then change to this (see also the Marshalling sample
chapter of the Unmanaged Exports docs):
[DllExport("Test", CallingConvention = CallingConvention.StdCall)]
static int Test([MarshalAs(UnmanagedType.BStr)] out string strout)
{
strout = "teststr";
return 0; // indicates success
}
而在Inno安装方面,使用 WideString
到:
And on the Inno Setup side with the use of WideString
to this:
[Code]
function Test(out strout: WideString): Integer;
external 'Test@files:testdll.dll stdcall';
procedure CallTest;
var
retval: Integer;
str: WideString;
begin
retval := Test(str);
{ test retval for success }
Log(str);
end;
这篇关于从具有非托管导出的C#DLL中返回一个字符串到Inno安装脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!