0

我正在尝试使用 C# (2.0/3.5) 中的一些旧版 Delphi 5 DLL。一些导出的函数是这样声明的:

function SimpleExport: OleVariant; stdcall;
function BiDirectionalExport(X: OleVariant; var Y: OleVariant): OleVariant; stdcall;

我希望使用 Marshal.GetDelegateForFunctionPointer 将它们设置为委托,但我无法正确地编组数据。我正在使用 LoadLibrary 和 GetProcAddress 的 kernel32 导入,因此我依靠 GetDelegateForFunctionPointer 来执行我的实际编组,而不是静态 p/invoke 声明。

由于 .NET 编组服务可以将对象编组为 COM OleVariants,因此我尝试了这个。但这会导致异常:“PInvoke 限制:无法返回变体。”。所以我想我需要使用自定义编组器。

将 Delphi 5 OleVariant 编组为 .NET 可读的正确方法是什么?

4

1 回答 1

1

由于 OleVariant 几乎可以是任何类型,并且 C# 中的所有类型都可以作为对象处理,因此我会尝试 system.object。

链接也可能会有所帮助。

于 2009-11-20T14:01:27.213 回答