我有一行代码:
Dim buf(1 To 255) As Byte
a$ = "hello"
Call CopyMemory(buf(1), ByVal a$, Len(a$))
我想在C#.NET中执行它。 C#.NET中上述行的替代方法是什么?
答案 0 :(得分:1)
string aString = "hello";
byte[] theBytes = Encoding.Default.GetBytes(aString);
答案 1 :(得分:0)
我设法解决了这个问题: -
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);
...........
}
然后可以通过其他应用程序从内存中获取它。