Marshaling Variant object

  • Thread starter Thread starter C. N. Sridhar
  • Start date Start date
C

C. N. Sridhar

Hi,
I'm writing a wrapper to a win32 dll in C#. I need to call
a method in DLL which has a Variant type reference
parameter.

How to marshal variant type from win32 (unmanaged code)
to C# (managed code)?

I tried using Marshal.GetObjectForNativeVariant(), but of
no use.

With regards,
-Sridhar
 
Hi Sridhar,

Here is my understanding of your question. You have a dll function with a
reference VARIANT parameter, and now you hope to call it in C#.
Here is my sample code below.
Did I misunderstand your meaning?
I do not know why you need to call Marshal.GetObjectForNativeVariant() to
Marshal the Variant data type.
If you have further question, please post some code, such as the dll
function declaration and the DllImport declaration in C#.

[StdDLL.dll]
long __declspec (dllexport) __stdcall Func11(VARIANT& MyArray){
MyArray.vt = VT_BSTR;
char* lpszText = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
MyArray.bstrVal =bstrText;
return 8;
}

[DllImport(@"c:\StdDLL.dll")]
public static extern int Func11(ref object var);
[STAThread]
static void Main(string[] args)
{
object s= new object();
int rt = Func11(ref s);
Console.WriteLine((string)s);
}

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Back
Top