vb.net 通过以下程序将字符串写到内存中,再输出时,中文乱码,怎么回事? 200
PublicFunctionStrToIntPtr(ByValinStrTextAsString)AsIntPtrDimnLenAsInteger=Len(inStrTe...
Public Function StrToIntPtr(ByVal inStrText As String) As IntPtr
Dim nLen As Integer = Len(inStrText)
'分配内存,以免内存区域给其他进程改写。
Dim ptr As IntPtr = Marshal.AllocHGlobal(nLen + 1)
Dim mstr As Byte() = Encoding.Unicode.GetBytes(inStrText)
For i = 0 To nLen - 1
Marshal.WriteByte(ptr, i, mstr(i * 2))
Next
Marshal.WriteByte(ptr, nLen, 0)
Return ptr
End Function 展开
Dim nLen As Integer = Len(inStrText)
'分配内存,以免内存区域给其他进程改写。
Dim ptr As IntPtr = Marshal.AllocHGlobal(nLen + 1)
Dim mstr As Byte() = Encoding.Unicode.GetBytes(inStrText)
For i = 0 To nLen - 1
Marshal.WriteByte(ptr, i, mstr(i * 2))
Next
Marshal.WriteByte(ptr, nLen, 0)
Return ptr
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询