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; ...
随机推荐
- pl/sql连接远程服务器
1.oracle提供了instantclient,下载instantclient-basic-win32-10.2.0.4.zip,将包解压存放到本地,如:D:\STUDY\instantclient ...
- 使用SignalR和SQLTableDependency跟踪数据库中记录的变动
原文地址:查看 SqlTableDependency是一个组件用来接收数据库的通知,包含在数据表上该记录的值的Inserted.Deleted或者Update操作. 备注:原文提供示例代码下载,但是j ...
- php不区分大小写
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android布局控件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- GPS数据处理 - 字符串函数的灵活应用
题目内容: NMEA- 0183协议是为了在不同的GPS(全球定位系统)导航设备中建立统一的BTCM(海事无线电技术委员会)标准,由美国国家海洋电子协会(NMEA- The National Mari ...
- Oracle RETURNING INTO 用法示例 .
The RETURNING INTO clause allows us to return column values for rows affected by DML statements. The ...
- python成长之路第三篇(2)_正则表达式
打个广告欢迎加入linux,python资源分享群群号:478616847 目录: 1.什么是正则表达式,python中得正则简介 2.re模块的内容 3.小练习 一.什么是正则表达式(re) 正则表 ...
- python super研究
# encoding=utf-8 class A(object): def __init__(self): print "初始化a" def run(self): print &q ...
- Dragon Balls--hdu3635(并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- MVC 分页获取数据 及点选按钮
@model PagedList<Lyxm.Entity.Suggestion>@using Webdiyer.WebControls.Mvc <div> <ul ...