示例1:分配一个新的内存地址给新变量

Point p;
// Initialize unmanged memory to hold the struct.
IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(p));
// Copy the struct to unmanaged memory.
Marshal.StructureToPtr(p, pnt, false);

// Create another point.
Point anotherP;

// Set this Point to the value of the 
// Point in unmanaged memory. 
anotherP = (Point)Marshal.PtrToStructure(pnt, typeof(Point));
Marshal.FreeHGlobal(pnt);


示例2:将一个字符串地址转换为字符串,以及获取字符串的地址:

IntPtr lpFileName;
string filename = Marshal.PtrToStringUni(lpFileName);
lpFileName = Marshal.StringToHGlobalUni(filename);

 

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
  • 2022-01-11
  • 2022-12-23
  • 2022-02-09
猜你喜欢
  • 2021-07-14
  • 2021-05-26
  • 2022-02-12
  • 2022-12-23
相关资源
相似解决方案