pass SAFEARRAY of BSTR from C++ to C# DLL RRS feed

  • General discussion

  • My code is soemthing like

    BSTR vb[20]; //heap alloc or _bstr_t no help

    SAFEARRAY* sa = SafeArrayCreateVector(VT_BSTR, 0, 20);

    long m =0;

    SafeArrayPutElement(sa, &m, vb);

    _exten_obj->GetData(sa); //C# DLL void GetData(string[]) in which correctly populates the string[]

    //vb contains unrecognized texts; regardless of char set to unset, UNICODE or MBCS

    SafeArrayGetElement(sa, &m, (void*)vb); //did not help

    Any idea?

    Tuesday, July 16, 2013 5:10 PM

All replies

  • Hello Shang Chou2,

    1. In order to accomplish what you aim to achieve in the above code, the signature of your C# function GetData() should be something like the following :

    public void GetData([In][Out] ref string [] stringArrayToFill);

    2. The IDL equivalent of the above function would be :

    HRESULT GetData([in, out] SAFEARRAY(BSTR)* stringArrayToFill);
    - Bio.

    Please visit my blog :

    Sunday, August 25, 2013 8:10 AM