V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yxd
V2EX  ›  C

c#调用 dll 动态库 传递结构体指针 要怎么传值

  •  
  •   yxd · 2018-12-06 15:07:19 +08:00 · 2025 次点击
    这是一个创建于 2169 天前的主题,其中的信息可能已经有所发展或是发生改变。

    动态库中结构体: struct CICinf { int Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9, Data10; int Data11, Data12, Data13, Data14, Data15, Data16, Data17, Data18, Data19, Data20; int Data21, Data22, Data23, Data24, Data25, Data26, Data27, Data28, Data29, Data30; };

    dll 动态库提供的函数:int __stdcall ICWriteXiMCard(int& CardType,int& Flag, CICinf* Inf );

    c#调用这个函数 参数要怎么传???

    我的 c#写法: [StructLayout(LayoutKind.Sequential)] public struct CICinf { public int Data1; public int Data2; public int Data3; public int Data4; public int Data5; public int Data6; public int Data7; public int Data8; public int Data9; public int Data10; public int Data11; public int Data12; public int Data13; public int Data14; public int Data15; public int Data16; public int Data17; public int Data18; public int Data19; public int Data20; public int Data21; public int Data22; public int Data23; public int Data24; public int Data25; public int Data26; public int Data27; public int Data28; public int Data29; public int Data30; }

          int cardType = 0;
          int flag = 1;
    	  CICinf Inf = new CICinf();
    	  int state = ICReadXiMCard(ref cardType,ref  flag,ref Inf);
          
           [DllImport(dllPath, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int ICReadXiMCard(ref int CardType, ref int Flag, ref  CICinf Inf);
        
        这样写  报托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配
        求 大佬 指导指导   万分感谢
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3530 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:44 · PVG 12:44 · LAX 20:44 · JFK 23:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.