C#访问非托管内存
2015-12-10 16:56
471 查看
示例1:分配一个新的内存地址给新变量
示例2:将一个字符串地址转换为字符串,以及获取字符串的地址:
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);
相关文章推荐
- C#当中的多线程_线程同步
- C#自定义DataGridViewColumn显示TreeView
- C#中的new和override
- C#获取当前应用程序所在路径及环境变量
- C#给图片添加水印完整实例
- C#操作注册表的方法详解
- C# 获取时间差状态
- C# 正则表达式
- C#XML的序列化与反序列化
- C# 通过Hook的方法 屏蔽快捷键
- C#实现网段扫描
- C#Soket组播
- 在C#中使用SerialPort类实现串口通信
- C++代码中使用C#的DLL
- C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe
- C# Using GC Efficiently
- 【转载】关于C#中Thread.Join()的一点理解
- C#中Virtual与override分别有什么用途
- C#面向对象--继承
- C#对本地文件重命名--适用于下载的图片、电视剧等奇怪名字的重命名