Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi i have a C++ DLL.
What i am doing is that i am passing memory address to my C++ dll where it write message on that address and i want to read the message from that memory address.
Here is my C++ function.
int _stdcall Test(int res, wchar_t *text)

Now in my C#.Net test app .. if i use unsafe char* .. i am getting proper output.
//Declaration
static extern unsafe int Test(char* msg); 
//Implementation
char* SerrMsg = stackalloc char[255];
Test(sMsg);
string emsg = new string(sMsg);

Now implementing in vb.net i am getting jst 1st character by using stringbuilder.
//Dec
Private Shared Function Test(ByVal msg As StringBuilder) As Integer
//Imp
Dim sMsg As New StringBuilder(400)
Test(sMsg)
eMsg= sMsg.ToString()

What is the replacement for char* in VB.Net ?
Help would be appreciated.
Thanks
Posted

It's a CharSet issue here, StringBuilder is the right choice of managed type.

When you use DllImport in VB, remember to set the CharSet to Unicode!
 
Share this answer
 
v2
Comments
Member 4581741 8-Apr-11 11:20am    
It worked.
Thanks
Sergey Alexandrovich Kryukov 9-Apr-11 22:36pm    
It should had worked indeed, my 5.
--SA
Nish Nishant 10-Apr-11 0:02am    
Thanks SA!
Dim sMsg As IntPtr = IntPtr.Zero or
Dim sMsgAs New StringBuilder("1234567890", 400) or
Dim rsp(400) As Byte

The data return need to see whether need to convert to ASCII or just sMsg.ToString.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900