将Delphi 5 OleVariant封送至C# [英] Marshaling Delphi 5 OleVariant to C#

查看:166
本文介绍了将Delphi 5 OleVariant封送至C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use some legacy Delphi 5 DLLs from C# (2.0/3.5). Some of the exported functions are declared as such:

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

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

I wish to set these up as delegates using Marshal.GetDelegateForFunctionPointer, but I'm having trouble getting the data Marshaled correctly. I'm using kernel32 imports of LoadLibrary and GetProcAddress, so I'm relying on GetDelegateForFunctionPointer to do my actual marshaling, not static p/invoke declarations.

由于.NET封送处理服务可以将对象封送至COM OleVariants,因此我尝试了此操作.但这会导致异常:"PInvoke限制:无法返回变体.".所以我想我需要使用自定义编组器.

Since the .NET marshaling services can marshal objects to COM OleVariants, I tried this. But this causes an exception: "PInvoke restriction: can not return variants.". So I'm figuring I need to use a custom marshaller.

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

What's the correct way to Marshal a Delphi 5 OleVariant into something .NET readable?

推荐答案

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

Since OleVariant can be nearly any type, and all types in C# can be handled as objects I would try system.object.

此链接可能会有所帮助.

这篇关于将Delphi 5 OleVariant封送至C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆