Click here to Skip to main content
15,878,430 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.
static extern unsafe int Test(char* msg); 
char* SerrMsg = stackalloc char[255];
string emsg = new string(sMsg);

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

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

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
Member 4581741 8-Apr-11 11:20am    
It worked.
Sergey Alexandrovich Kryukov 9-Apr-11 22:36pm    
It should had worked indeed, my 5.
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