lovple
lovple
2016-01-18 13:49
采纳率: 0%
浏览 1.7k

C#调用C++动态库参数转换

用C#调用C++封装好dll,这个动态库的方法如下:long GetImageData( LPCTSTR i_strImageID, long i_nPhysicalX, float i_fMag,
long *o_nPhysicalWidth, long *o_nPhysicalHeight, void *i_pBuffer, long *io_nBufferSize) ,请问对应的C#方法参数如何写?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • caozhy
     int GetImageData( StringBuileder i_strImageID, int i_nPhysicalX, float i_fMag, 
    ref int o_nPhysicalWidth, ref int o_nPhysicalHeight, intptr i_pBuffer, ref int io_nBufferSize) 
    
    点赞 评论
  • lovple
    lovple 2016-01-18 14:21

    非常感谢,但测试了一下,报以下错误:Additional information: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏

    点赞 评论
  • fei13148687
    狒狒空空 2016-01-19 02:01

    你可以参考这样写:
    C++
    extern "C"__declspec(dllexport)
    void GetImageData(char*strImageID,int i_nPhysicalX, float i_fMag, int o_nPhysicalWidth,
    int o_nPhysicalHeight, ushort* i_pBuffer, int* io_nBufferSize)

    c#
    [DllImport("xxxxx.dll",EntryPoint="GetImageData")]
    public static unsafe extern void GetImageData(char*strImageID,int i_nPhysicalX, float i_fMag, int o_nPhysicalWidth,
    int o_nPhysicalHeight, ushort* i_pBuffer, int* io_nBufferSize)

    c#中
    string strImageID_ptr="A0001"
    char*strImageID = (char*)Marshal.StringToCoTaskMemAnsi(strImageID_ptr)
    ushort[,] i_pBuffer_t=new double[10,10]
    ushort* i_pBuffer =&i_pBuffer_t[0,0]

    点赞 评论

相关推荐