IntPtr问题
public aaa(IntPtr myPtr,int left, int top, int width, short height)
这里myPtr应该是对应到一块内存,你需要查看aaa函数是如何把myPtr转化成它内部要使用的结构体的(一般都是结构体,也可能是其它对象,比如数组)。
然后,你需要在你的托管代码中,定义该结构体,使用StructLayout特性,对结构体的字段使用MarshalAs特性,类似这样:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Size = 13)]
public struct A101220Output
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
public string TransactionAccountID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public string IsAuthenticated;
}
//创建托管对象
A101220Output output = new A101220Output ();
output.TransactionAccountID = "11000000841";
output.IsAutienticated = "false"; //分配非托管内存,并获取非托管内存地址起始位置指针
int size = Marshal.SizeOf(output);
IntPtr buffer = Marshal.AllocHGlobal(size); try
{
//将托管对象拷贝到非托管内存
Marshal.StructureToPtr(output, buffer, false); //调用非托管方法
aaa.(buffer,0,0,640,480);
}
finaly
{
//释放非托管内存
Marshal.FreeHGlobal(buffer);
}
IntPtr问题的更多相关文章
- C# byte[]、struct、intptr等的相互转换
1.struct byte[]互相转换 //struct转换为byte[] public static byte[] StructToBytes(object structObj) { int siz ...
- 为什么C#中要设计IntPtr?
示例代码: IntPtr vertex = someObj.Get().Lock(0, someObj.Get().GetSizeInBytes(), HardwareBuffer.LOCKOPTIO ...
- C# IntPtr转换为Byte[]
[DllImport("OpenNetStream.dll")] public static extern int OpenSDK_Data_GetDevList(IntPtr s ...
- CloseHandle(IntPtr handle)抛异常
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static ext ...
- EmguCV 如何从数组中创建出IntPtr
需要添加引用:System.Runtime.InteropServices 举例如下: float[] priors={1,10}; IntPtr intPtrSet = new IntPtr(); ...
- C#中的IntPtr类型
本文转自:http://zhidao.baidu.com/question/22825956.html 问: c#中无法将类型“int”隐式转换为“System.IntPtr” 这个是我引用了一个ap ...
- 任意类型转换为IntPtr
之前,将数组.结构体等转换为IntPtr使用的是Marshal.Copy().Marshal.StructureToPtr(),但是有个问题自定义的结构体数组没法这样转化,一般网上给出的解决方法就是通 ...
- (转)C#进行图像处理的几种方法(Bitmap,BitmapData,IntPtr)
转自 http://blog.sina.com.cn/s/blog_628821950100wh9w.html C#进行图像处理的几种方法 本文讨论了C#图像处理中Bitmap类.BitmapData ...
- c# 读取IntPtr 中的数据 z
c++的写法是这样的: LRESULT CPictureQueryDlg::OnQueryPicNty(WPARAM wp, LPARAM lp) { EnableWindow(TRUE); BYTE ...
- [转载]C#中int和IntPtr相互转换
方法一. int转IntPtr int i = 12; IntPtr p = new IntPtr(i); IntPtr转int int myi = (int)p; ...
随机推荐
- mysql 5.5源码包安装
注:由于mysql5.5的源码包安装与mysql之前的版本安装方法不同,故写一篇随笔记录.5.5的版本不再是./configure make make install 这里用到了cmake了,cmak ...
- android实现透明和半透明效果
从透明到半透明时一个值的变化过程. #00000000(全透明)——#e0000000(半透明) 如果觉得半透明的效果太暗淡.可以设置成#60000000,#80000000,#a0000000等等
- locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
安装好CentOS后,第一次进入系统使用locate命令,结果出现:locate: can not stat () `/var/lib/mlocate/mlocate.db': No such fil ...
- 【IOS学习基础】文件相关
一.沙盒(SandBox) 1.沙盒机制 1> 每个应用都有属于自己的存储空间,即沙盒. 2> 应用只能访问自己的沙盒,不可访问其他区域. 3> 如果应用需要进行文件操作,则必须将文 ...
- 在T-SQL语句中访问远程数据库(openrowset/opendatasource/openquery)
1.启用Ad Hoc Distributed Queries 在使用openrowset/opendatasource前搜先要启用Ad Hoc Distributed Queries服务,因为这个服务 ...
- hadoop高可用集群搭建小结
hadoop高可用集群搭建小结1.Zookeeper集群搭建2.格式化Zookeeper集群 (注:在Zookeeper集群建立hadoop-ha,amenode的元数据)3.开启Journalmno ...
- Single Number,Single Number II
Single Number Total Accepted: 103745 Total Submissions: 218647 Difficulty: Medium Given an array of ...
- 理解中WebAPI的属性和相关操作 FormBody和 FormUri等(WebAPI 二)
1.FromUri使用 将数据通过url方式传递.我们需要在webapi方法标明,这个参数只接受url中参数的值, $("#Save").click(function () { $ ...
- Android 部分机型GridView四周默认间距
在测试兼容性时候,部分机型,比如联想和一加等手机,在使用Gridview的时候,会默认四周有默认边距,10dp左右. 这时候需要设置 android:listSelector="@andro ...
- DEP受保护的问题(尤其是Outlook)
We see this issue quite regularly as we use MAPI and lots of our users run our application on TS. Of ...