Varaint ---> COM to .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duncan Winn

    #1

    Varaint ---> COM to .NET

    I am passing back a Variant* from COM to .NET. The pointer actually holds a
    void**. i.e.

    void ** row_array;
    row_array = (void**)new byte[100];

    row_array[0] = (void*)70186;
    row_array[1] = (void*)"701.86" ;
    row_array[2] = (void*)true;
    row_array[2] = (void*)"duncan" ;

    Variant variant_array;
    Variant *variant_array_ ptr = &variant_arr ay;
    variant_array_p tr->byref = row_array;
    return *variant_array_ ptr;


    However I do not know how to retrieve the information in.Net.
    At present I have placed the returned Variant into an object but this does
    not seem any good?

    Any suggestions???


  • Duncan Winn

    #2
    Re: Variant ---> COM to .NET

    Thanks Nicholas,

    I have done what you suggested, i.e.:

    SAFEARRAY * pMySafeArray = ( SAFEARRAY* ) new
    long[sizeof(SAFEARRA Y)];
    pMySafeArray->cDims = 1; / dimensional array
    pMySafeArray->fFeatures= FADF_FIXEDSIZE; //flags (fixed size)
    pMySafeArray->cbElements = sizeof(int_ptr) ; //size of one element
    pMySafeArray->cLocks = 0; //lock count
    pMySafeArray->pvData = row_array; //pointer to the array data
    pMySafeArray->rgsabound[0].lLbound = 0;
    pMySafeArray->rgsabound[0].cElements =
    sizeof(row_arra y)/sizeof(int_ptr) ;
    return pMySafeArray;

    However I am not sure how to use this in .NET. I can't seem to cast it
    directly into a C# array??

    Any further suggestions???


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Variant ---> COM to .NET

      Duncan,

      There are a few more errors here. The SAFEARRAY structure is used to
      store array information in COM. You do not create a SAFEARRAY by using the
      new keyword.

      I think you should take a look at the Dr. GUI article titled "Dr. GUI
      and COM Automation, Part 3: More on COM's Fabulous Data Types", specifically
      the section titled "Safe Arrays", located at (watch for line wrap):

      http://msdn.microsoft.com/library/de...rgui042099.asp

      Once you have this, you can learn how to return your array from your COM
      object and then you can have it marshaled as an object array.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - nicholas.paldin o@exisconsultin g.com


      "Duncan Winn" <test@test1.co. uk> wrote in message
      news:%239aJLE5T DHA.2252@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Thanks Nicholas,
      >
      > I have done what you suggested, i.e.:
      >
      > SAFEARRAY * pMySafeArray = ( SAFEARRAY* ) new
      > long[sizeof(SAFEARRA Y)];
      > pMySafeArray->cDims = 1; / dimensional array
      > pMySafeArray->fFeatures= FADF_FIXEDSIZE; //flags (fixed size)
      > pMySafeArray->cbElements = sizeof(int_ptr) ; //size of one element
      > pMySafeArray->cLocks = 0; //lock count
      > pMySafeArray->pvData = row_array; //pointer to the array data
      > pMySafeArray->rgsabound[0].lLbound = 0;
      > pMySafeArray->rgsabound[0].cElements =
      > sizeof(row_arra y)/sizeof(int_ptr) ;
      > return pMySafeArray;
      >
      > However I am not sure how to use this in .NET. I can't seem to cast it
      > directly into a C# array??
      >
      > Any further suggestions???
      >
      >[/color]


      Comment

      Working...