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

  • 相关阅读:
    LeetCode Subarrays with K Different Integers
    LeetCode Repeated DNA Sequences
    为什么要使用静态方法
    String,StringBuilder,StringBuffer
    汉诺塔递归算法
    设计模式之代理模式
    设计模式之单例设计模式
    设计模式之工厂方法和抽象工厂
    设计模式之模板方法
    并发技巧清单(1)
  • 原文地址:https://www.cnblogs.com/gaara-zhang/p/10071047.html
Copyright © 2011-2022 走看看