我有一行代码:
Dim buf(1 To 255) As Byte
a$ = "hello"
Call CopyMemory(buf(1), ByVal a$, Len(a$))我想在C#.NET中执行它。在C#.NET中,上面这行代码的替代方案是什么?
发布于 2014-01-21 04:45:46
string aString = "hello";
byte[] theBytes = Encoding.Default.GetBytes(aString);请参阅Encoding.GetBytes和Encoding.Default
发布于 2014-01-22 19:31:49
我设法解决了这个问题:
string aString = text;
byte[] theBytes = System.Text.Encoding.Default.GetBytes(aString);
//to copy to memory use the following:-
// Marshal the managed struct to a native block of memory.
int myStructSize = theBytes.Length;
IntPtr pMyStruct = Marshal.AllocHGlobal(myStructSize);
try
{
Marshal.Copy(theBytes, 0, pMyStruct, myStructSize);
...........
}然后,其他应用程序可以从内存中提取此信息。
https://stackoverflow.com/questions/21234058
复制相似问题