none
Calling C++ method with LPCTSTR & SAFEARRAY from VB.NET RRS feed

  • Question

  • All,

       We have a C++ function looks like this:

    int _stdcall ResultsParse(LPCTSTR outputBuffer, SAFEARRAY ** abs)
    {

    ******

    ******

    *****

    }

    This function will parse content of outputbuffer and put it on SafeArray as structure.

    From VB6 we used to call above method as follows:

    Declaration part:

    Private Declare Function ResultsParse Lib "abc.dll" (ByVal outputBuffer As String, ByRef output() As udt) As Long

    Calling part:

    Dim arr() As MyType

    dim rc as Long = ResultsParse(outputBuffer, arr())

    Note: Here MyType is Type(UDT) in VB6 & outputbuffer is an actual content that we need to parse. Once the data is parsed respective data is copied on arr from C++ code using C++ structures. Also length on the array will be determined by C++ code.

    Now we migrated the code to VB.NET when we make the same kind of call to C++ code we are getting errors.

    During our analysis we found that VB6 arrays are same as SafeArrays so it is working but VB.NET arrays are managed arrays and are different from SafeArray.

    Can any one help me on calling above mentioned C++ code from VB.NET using structures/classes??

    Note: We do not know length of structure to be untill it is processed. Also in some cases we may have structure inside another structure too.

    Thanks in advance,

    Kiran


    Rama Kiran Kanagala

    Monday, October 1, 2012 1:51 PM

Answers