Reputation: 9724
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. What is the alternative for the above line in C#.NET?
Upvotes: 1
Views: 853
Reputation: 9724
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..
Upvotes: 0
Reputation: 30408
string aString = "hello";
byte[] theBytes = Encoding.Default.GetBytes(aString);
See Encoding.GetBytes and Encoding.Default
Upvotes: 1