views:

287

answers:

1

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;

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.

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.

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

A: 

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

Also this link may be helpful.

Robert Love
Using System.Object with the default marshaling services doesn't work unfortunately. I've updated my question to reflect this.
ulrikj