Hi,
I am using C++ dll (dynamic-linked library, not COM ATL) in my VB.NET
program. when i pass a VB.Net 'String' object to one of the function
of dll that modifies the string, it works fine. dll code is like:
long UpdateString(LPWSTR str)
{
wcscpy( str, L"result" );
return wcslen( str );
}
and function declaration in VB is like:
<DllImport("TestDllEx.dll", EntryPoint:="UpdateString",_
SetLastError:=True, _
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function _
UpdateStringA(ByVal str As String) As Integer
End Function
Now the problem is when i pass a VB Structure that has an 'Integer'
and a 'String' member to dll function to modify, it only copies one
character to the String member whereas Integer member is modified
successfully. dll structure & function are like:
struct myst
{
long x;
LPWSTR s;
};
long UpdateStruct(myst *st)
{
st->x = 100;
wcscpy( st->s, L"result" );
return wcslen( st->s );
}
in VB.Net they are like:
Public Structure myst
Dim x As Integer
Dim s As String
End Structure
<DllImport("TestDllEx.dll", EntryPoint:="UpdateStruct",_
SetLastError:=True, _
CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function _
UpdateStructA(ByRef st As myst) As Integer
End Function
The function returns correct size i.e. 6 (length of string "result").
But in VB i get only "r" in the string member.
Can anyone help??
Thanks