By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

usnig C++ dll from VB.NET

P: n/a
TF
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
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.