Pinvoke String problem

  • Thread starter Marco Mariv via DotNetMonster.com
  • Start date
M

Marco Mariv via DotNetMonster.com

Hi group,

i have a problem.
I don't succeded to pass string from Unmanaged Code to managed code.
I have this situation:

Unmanaged Code:
------------------------
DRIVER_API int __stdcall
Read (LPWSTR data,int *len,int *lenwct)
{
..
...
....
char lpstr[255];
wchar_t szTmp[255];
..
...
....

*len = strlen(lpstr);
*lenwct = wcstombs(lpstr,szTmp,255);
..
...
....
return 1;

}

Managed Code (VB.NET):
------------------------
<DllImport("MyDriver.dll", EntryPoint:="Read", CallingConvention:=CallingConvention.Winapi, SetLastError:=True)> _
PublicFunction Read(ByVal data As StringBuilder, ByRef len As Int64,ByRef lenwct As Int64) As Integer
End Function

-------
When i (p)invoke this function i have this responce:
len = 120
lenwct = 6
data ="??????||||||"

why?

I dont' know how to convert a string (char *) to LPWSTR.
How can i pass a string from Unmenaged to menaged code.

I have use StringBuilder. Is it a correct solution?

Help me!
 
M

Marco Mariv via DotNetMonster.com

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top