V
Vincent Schmid
Hello,
I've declared a VB callback Sub which is called by an unmanaged DLL (code
below). The PData parameter is a pointer to a memory bloc which is allocated
and freed by the dll as necessary.
The RequestFunc should read a string pointed by PData, and replace it by
another one. The problem arises when the Sub tries to write the answer :
there is an error when calling Marshal.PtrToStringAnsi. (The RequestFunc is
not supposed to free the memory bloc pointed by PData)
What's wrong with the following code ? (note : the buffer is allocated for
sure, and is large enough)
Many thanks for comments,
Sincerely
Vincent
Sub RequestFunc(ByVal PData As IntPtr, ByVal DataSize As Int32)
Dim Request As String
Dim Answer As String
Request = Marshal.PtrToStringAnsi(PData, DataSize)
MsgBox(Request)
Answer = "This is the answer"
Marshal.StructureToPtr(Answer, PData, False)
End Sub
I've declared a VB callback Sub which is called by an unmanaged DLL (code
below). The PData parameter is a pointer to a memory bloc which is allocated
and freed by the dll as necessary.
The RequestFunc should read a string pointed by PData, and replace it by
another one. The problem arises when the Sub tries to write the answer :
there is an error when calling Marshal.PtrToStringAnsi. (The RequestFunc is
not supposed to free the memory bloc pointed by PData)
What's wrong with the following code ? (note : the buffer is allocated for
sure, and is large enough)
Many thanks for comments,
Sincerely
Vincent
Sub RequestFunc(ByVal PData As IntPtr, ByVal DataSize As Int32)
Dim Request As String
Dim Answer As String
Request = Marshal.PtrToStringAnsi(PData, DataSize)
MsgBox(Request)
Answer = "This is the answer"
Marshal.StructureToPtr(Answer, PData, False)
End Sub