CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    Why does this SAFEARRAY not work?

    I am trying to send an array of strings from a VB client to a C++ server and am having difficulty. When I call SafeArrayAccessData(), the function returns E_UNEXPECTED, meaning that it could not access the data in the SAFEARRAY. Please someone point out what is the problem with my code!


    ///This is the C++ Server
    ///////////////////////
    void ServerClass::PrintBStringArray(const VARIANT FAR& inval)
    {
    if((inval.vt & VT_ARRAY) == 0)
    return; //Not an array
    if((inval.vt & VT_BSTR) == 0)
    return; //Not filled with BSTRs

    SAFEARRAY FAR *psa=inval.parray;
    BSTR HUGEP *bstrArray;
    HRESULT hr;
    CString strg;
    hr=SafeArrayAccessData(psa, (void HUGEP* FAR*)&bstrArray);
    if (FAILED(hr))
    {
    AfxMessageBox("Problem with array");
    if(hr==E_INVALIDARG) AfxMessageBox("Invalid SafeArray!");
    if(hr==E_UNEXPECTED) AfxMessageBox("Unexpected Error");
    }
    strg=CString(bstrArray[0]);
    AfxMessageBox(strg);
    SafeArrayUnaccessData(psa);
    return;
    }

    /////////////////////////////
    //This is the VB Client
    ////////////////////////////
    Private Sub Command3_Click()
    Dim StrArr(4) As String
    StrArr(0) = "This is entry 1"
    StrArr(1) = "This is the second entry"
    StrArr(2) = "this is number three"
    StrArr(3) = "The last entry..."
    Set Myobj = CreateObject("AutoDLLTest.ServerClass")
    Myobj.PrintBStringArray StrArr()
    End Sub




    Result: UNEXPECTED ERROR!

    Is the parameter passed in (const VARIANT FAR& inval) OK? This is what ClassWizard created for me, and it appears to work OK....

    Thanks, Jeff


  2. #2
    Join Date
    May 1999
    Location
    13 N 77 E
    Posts
    183

    Re: Why does this SAFEARRAY not work?

    try making the C++ server interface method take the VARIANT* as [in,out]


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