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; ...
随机推荐
- 解决升级Xcode后插件不能使用的问题
从Xcode 5开始,苹果要求加入UUID证书从而保证插件的稳定性.因此Xcode版本更新之后需要在插件的Info.plist文件中添加当前Xcode的UUID. 具体步骤如下: 1.获取Xcode的 ...
- G - Bullseye
Description A simple dartboard consists of a flat, circular piece of cork with concentric rings draw ...
- 浅说CPU并行计算与GPU并行计算
最近在学一门课,叫做“C++与并行计算”.要用到多CPU(进程)并行的原理,实现语言是C++的MPI接口.联想到上学期用到CUDA C/C++来做并行计算,就对这两门语言做一个总结,分享下自己关于并行 ...
- 原生化:AnDevCon 2014 McVeigh 的主题演讲
作者:Jeff McVeigh(Intel) 基于(至少部分)NDK的原生安卓应用程序占现在前1000 强的 60% 以上.该增长的原因很简单:开发商需要为用户提供超卓的体验(包括灵敏的反应.与丰富的 ...
- flask twisted 结合方案
from flask import Flask, render_template, g app = Flask(__name__) @app.route("/") def inde ...
- Python Challenge 过关心得(0)
最近开始用Openerp进行开发,在python语言本身上并没有什么太大的进展,于是决定利用空闲时间做一点python练习. 最终找到了这款叫做Python Challenge(http://www. ...
- Linux下MySQL安装及命令使用
先rpm -qa mysql 查看是否安装 yum list |grep mysql 查看MySQL的一些包 yum install -y mysql-server mysql mysql-devel ...
- 字符串水题(hdoj1049)
Problem Description Password security is a tricky thing. Users prefer simple passwords that are easy ...
- Objextive-C几道小题目笔记
//掷骰子题,掷骰子100次,输出每个号出现的次数 void one() { for (int i=1; i<=100; i++) { int a = arc4random() % 6 +1; ...
- MVC 分页获取数据 及点选按钮
@model PagedList<Lyxm.Entity.Suggestion>@using Webdiyer.WebControls.Mvc <div> <ul ...