首页 > 编程知识 正文

北京奔驰c200,c代表什么

时间:2023-05-06 17:09:52 阅读:36468 作者:805

IntPtr是包装调用WindowsAPI函数的指针的类,根据平台的不同,底层指针可以是32位或64位。 表示平台特定的指针或句柄类型,C#主要用于调用封装在C C中的DLl库。 主要介绍IntPtr的一般使用方法

1.int类型与IntPtr类型之间的转换

用户系统; using system.collections.generic; using System.Linq; using system.runtime.interop services; using System.Text; using System.Threading.Tasks; namespacemyintptr { class program { staticvoidmain [ ] args } { intn value1=10; int nValue2=20; //all och全局(intcb ) :使用指定的字节数从进程的非托管存储器分配存储器。 intptr ptr1=marshal.all och全局(sizeof (int ); intptr ptr2=marshal.all och全局(sizeof (int ); //write int 32 (intptr,int val ) :将32位有符号整数值写入非管理存储器。 //int-intptr marshal.write int 32 (ptr 1,nValue1); Marshal.writeint32(ptr2,nValue2); 从//readint32(intptrptr,int ofs ) :非托管内存中指定了32位有符号整数(/intptr-intintnval1=marshal.readint 32 ) ptr 1,0 ) int nval2=marshal.readint 32 (ptr 2,0 ); //freehglobal(intptrhglobal ) :释放以前从进程的非托管存储器中分配的存储器。 Marshal.freehglobal(ptr1; Marshal.freehglobal(ptr2; } }} 2.string类型与IntPtr之间的转换

用户系统; using system.collections.generic; using System.Linq; using system.runtime.interop services; using System.Text; using System.Threading.Tasks; namespacemyintptr { class program { staticvoidmain [ ] args } { stringstr=' aa '; intptr strptr=marshal.stringtohglobalansi (str ); stringss=marshal.ptrtostringansi (strptr ); Marshal.freehglobal(strptr; } }} 3.结构体与IntPtr之间的转换

用户系统; using system.collections.generic; using System.Linq; using system.runtime.interop services; using System.Text; using System.Threading.Tasks; namespacemyintptr { class program } publicstructstuinfo { public string name; 公共字符串生成器; 公共int age; 公共int height; }staticvoidmain(string[]args ) { stuInfo stu=new stuInfo ) { Name='繁荣的羊',Gender='男',Age=23,height=113 //声明大小相同的内存空间intptr intptr=marshal.all och全局(nsize )//intptr-struct marshal.structuretoptr (stu,intptr //struct-intptrstuinfoinfo=(stuinfo ) marshal.ptrtostructure(intptr,typeof ) stuinfo ); 控制台. read key (; } }

转载自:https://www.cnblogs.com/快乐吐司/p/10274197.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。