zoukankan      html  css  js  c++  java
  • c# 调用c++dll二次总结

    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#自己的。

  • 相关阅读:
    subprocess 子进程模块
    3.5 魔法方法
    ThinkPHP中,display和assign用法详解
    linux常用指令
    退出当前Mysql使用的db_name 的方式
    PHP中GD库是做什么用的? PHP GD库介绍11111111
    include跟include_once 以及跟require的区别
    全局变量跟局部变量
    关于define
    创建、删除索引---高级部分
  • 原文地址:https://www.cnblogs.com/gaara-zhang/p/10071047.html
Copyright © 2011-2022 走看看