CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    126

    c# and variant types

    Hey all.

    I have this COM server and a method on it takes a variant type, how can i declare a pass a variant in c#?

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: c# and variant types

    What does tlbimp.exe have to say about the dll ? Add the dll as a reference to your project and see what the wrapper class does.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: c# and variant types

    A COM VARIANT type (as well as IUnknown* and IDispatch*) is marshalled as a System.Object. Say you have a function like this
    Code:
    HRESULT Open(
      [in] VARIANT* FileName,
      [in] VARIANT options);
    Then you can do it like this:
    Code:
    object fileName = @"c:\test.txt";
    object options = 0; // some flags
    Open(ref fileName, options);
    The COM attribute/C# modifier table is :
    Code:
    [in]                - > <no_modifier>
    [out]             - > out
    [in, out]        - > ref
    [out, retval]  - > <return_value>
    See this link http://msdn.microsoft.com/library/de...forobjects.asp for more.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Feb 2005
    Posts
    126

    Re: c# and variant types

    cheers cilu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured