我在 C++ 中有这些声明:
struct objectStruct;
int positionMemory = getPosition();
short size = getSize();
void *allocatedObject; // Originally, it is in C#: IntPtr allocatedObject { get; private set; }
byte[] byteName = Encoding.ASCII.GetBytes("Hello There");
我想将这些代码行从 C# 转换为 C++:
string result = Marshal.PtrToStringAnsi(new IntPtr(positionMemory), size);
Marshal.StructureToPtr(objectStruct, new IntPtr(positionMemory), true);
Marshal.Copy(byteName, 0, new IntPtr(positionMemory), size);
long posInMemory = allocatedObject.Offset(size).ToInt64();
我对编组不熟悉。