unclepauly 6 Light Poster

hi,

well i have posted this on two other forums without success, hoprfuly you guys can help me !

the scenario - i have a native c++ dll that creates and initializes a string, which is a char array.

char pRet[1024];
memset(pRet, 0, 1024);
strcpy(pRet, "change me!");

the c++ dll then fires a callback function, and the callback function must change the value of the string. however, the callback function is in a VB.NET app.

the callback function is defined in the c++ dll as :

typedef VOID (WINAPI *CALLBACK_ROUTINE)(char*  pRet);

so the delegate type that i have created in the VB.NET app is:

Public Delegate Sub CALLBACK_ROUTINE(ByVal pRet As IntPtr)

then the actual VB.NET callback function itself is like this:

Private Sub pCallback(ByRef pRet As IntPtr)
     pRet = Marshal.StringToCoTaskMemAnsi("response from vb.net app !")

     ' do not call CoTaskMemFree because the C++ dll created the char array and will therefore be responsible for freeing the memory !
End Sub

however when the C++ dll has finished calling this VB.NET callback, pRet still says 'change me !'.

so how do i define the delegate type (assuming what i have done is wrong) and how do i modify the value of the string in the VB.NET callback function, such that the c++ dll 'sees' this change ? in other words how do i write the code so that the C++ dll and the VB.NET app share and access the same string buffer ?

many thanks in advance for any help, this has stumped me for days !