[英]How do I implement CopyMemory (VB6) in C#.NET?
I have a line of code: 我有一行代码:
Dim buf(1 To 255) As Byte
a$ = "hello"
Call CopyMemory(buf(1), ByVal a$, Len(a$))
I want to execute it in C#.NET. 我想在C#.NET中执行它。 What is the alternative for the above line in C#.NET? 在C#.NET中上述行的替代方法是什么?
string aString = "hello";
byte[] theBytes = Encoding.Default.GetBytes(aString);
See Encoding.GetBytes and Encoding.Default 请参见Encoding.GetBytes和Encoding.Default
I have managed to solve this issue:- 我设法解决了这个问题:
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);
...........
}
This can then be picked up from the memory by other application.. 然后可以由其他应用程序从内存中拾取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.