VB.Net中的Char指针 [英] Char pointer in VB.Net
本文介绍了VB.Net中的Char指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有一个C ++ DLL。
我正在做的是我将内存地址传递给我的C ++ dll,它在该地址上写入消息,我想从该内存地址读取消息。
这是我的C ++函数。
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)
现在在我的C#中.Net测试app ..如果我使用不安全的char * ..我得到正确的输出。
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);
现在在vb.net中实现我使用stringbuilder获得第j个字符。
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()
VB.Net中char *的替代品是什么?
帮助将不胜感激。
谢谢
What is the replacement for char* in VB.Net ?
Help would be appreciated.
Thanks
推荐答案
这是一个CharSet
问题,StringBuilder
是托管类型的正确选择。
在VB中使用DllImport
时,记得设置CharSet
到Unicode
!
It's aCharSet
issue here,StringBuilder
is the right choice of managed type.
When you useDllImport
in VB, remember to set theCharSet
toUnicode
!
Dim sMsg As IntPtr = IntPtr.Zero或
Dim sMsgAs新的StringBuilder(1234567890,400)或
Dim rsp(400)As Byte
数据返回需要查看是否需要转换为ASCII或只是sMsg.ToString。
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.
这篇关于VB.Net中的Char指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文