c# 调用c++dll二次总结
2024-10-19 02:20:24
1.pinvoke结构不对称,添加语句(网上有)
2.含回调函数,成员参数的结构体必须完全,尽管自己用不到。
3.加深对c++指针的理解。一般情况下,类型加*等效于c++中的ref。但对于short* 、float*等,根据具体的内容来进行确定类型。
这次例子用到的内容就是地址。c#用IntPtr来代替。
而传参的时候,c#这样声明与运用:
int iImageW = pY16Info.ImgWidth;//图像宽
int iImageH = pY16Info.ImgHeight;//图像高
IntPtr pOpque = pY16Info.pOpque;
int size = Marshal.SizeOf(typeof(float));
IntPtr infosIntptr = Marshal.AllocHGlobal(pY16Info.ImgWidth * pY16Info.ImgHeight * size);
GD_DATAS = new float[pY16Info.ImgWidth * pY16Info.ImgHeight];
if ((int)GD_MTC_ERROR_CODE.NO_ERROR == GD_MTC_SDK_GetTempMatrix(pOpque, infosIntptr))//获取实时全图温度
{
for (int inkIndex = 0; inkIndex < pY16Info.ImgWidth * pY16Info.ImgHeight; inkIndex++)
{
IntPtr ptr = (IntPtr)((UInt32)infosIntptr + inkIndex * size);
GD_DATAS[inkIndex] = (float)Marshal.PtrToStructure(ptr, typeof(float));
}
}
else
{
GD_DATAS = null;
}
4.当遇到棘手问题时候,简便做法就是unsfe来写c#,c++指针参数照搬。但是取地址等其他操作还得用c#自己的。
最新文章
- 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation
- 一个链式调用 setTimeout的例子
- 【LeetCode】16. 3Sum Closest
- oracle 10g升级到11g
- tp28xx port pin (open-drain )and (push-pull) 和open collector)
- 在unity的scene中画五角星
- RecyclerView.Adapter
- Effective C++笔记之Item49【了解new-handler的行为】
- MySQL索引(1)
- Visual Studio中Image Watch的使用
- Visual Studio 2015 激活码
- MERGE INTO 解决大数据量 10w 更新缓慢的问题
- git merge以及比较两个repo
- vuejs、eggjs、mqtt
- 返回最小的k个数
- 手工释放linux内存------/proc/sys/vm/drop_cache
- 什么是'脑分裂(split brain)'?
- 【RF库Collections测试】Dictionary Should Contain Value
- Android 4.4 KitKat终于支持录屏(Screen Recording)了!
- JavaScript 数组遍历方法的对比
热门文章
- Android Studio 2.3.3 出现Error:(26.13) Fail to resole: com.android.support.appcompat永久解决方法
- 树莓派3B+学习笔记:10、使用SSH连接树莓派
- python 文件读取方法详解
- 文件句柄W模式
- 20155330 2016-2017-2 《Java程序设计》第二周学习总结
- 20155338 2016-2017-2 《JAVA程序设计》课程总结
- WPF中。。DataGrid 实现时间控件和下拉框控件
- sql语句-3-聚合数据查询
- [BZOJ2961]共点圆-[凸包+cdq分治]
- hadoop 、hive 的一些使用经验。