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

    returning array and VARIANT problem

    I am attempting to use an ActiveX control and I need to access the return from a function defined in the control wrapper class as :
    VARIANT C_Protocol::GET_WORKTABLE_DATA(BSTR* sWorktableFile)



    I have a VB example that calls it with

    Dim vWorkTable As Variant

    With AtiveXCtrl

    vWorkTable = .THE_FUNCTION (...)

    What I want to know is what type do I equate the call to in C++. It is defined as a

    variant/string (1 to 12, 1 to 2)

    in VB.

    Thanks,

    Paul




  2. #2
    Join Date
    Oct 2001
    Location
    CA,USA
    Posts
    60

    Re: returning array and VARIANT problem

    You can use CString.
    See my example at
    http://atcsoft.freeservers.com/thele...TL/sample2.htm


    Please rate the article if it is of any use to you. This encourages me to reply more and more and more.

  3. #3
    Join Date
    Aug 2001
    Posts
    48

    Re: returning array and VARIANT problem

    Thanks for the reply.

    As far as I can tell this is not quite what I was asking for. I am writing a C++ function that calls up a VB ActiveX control. The control returns an array. I need to know how IO can get access to this array from my C++ code.

    Thanks again,

    Paul


  4. #4
    Join Date
    Sep 2001
    Location
    Bristol, England
    Posts
    321

    Re: returning array and VARIANT problem

    Have a look at the vt member of the VARIANT, which will tell you what type it is. If it's an array (VT_ARRAY) then Automation provides a load of SafeArrayXXX functions to manipulate the underlying SAFEARRAY object (the parray member of the VARIANT). For example:VARIANT v = <function call>
    if (v.vt & VT_ARRAY)
    {
    // get the dimensions of the array
    UINT nDim = SafeArrayGetDim(v.parray);

    // you can get the size of the array using
    // SafeArrayGetLBound and SafeArrayGetUBound

    void* pData;

    HRESULT hr = SafeArrayAccessData(v.parray,&pData);
    if (SUCCEEDED(hr))
    {
    // pData now points to the array data
    SafeArrayUnaccessData(v.parray);
    }
    }




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