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?