Advertisement

C#使用C++ dll对照表合集

阅读量:

函数调用过程中可能出现堆栈结构失衡的问题。其潜在原因可能在于托管环境下的PInvoke签名与非托管目标函数的定义存在差异,此时只需在dllimport声明中添加CallingConvention参数即可解决。

[DllImport(PCAP_DLL, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] 需特别关注C++语言与.NET框架间的数据类型映射关系:


复制代码
 //c++:char * ---- c#:string //传入参数

    
   //c++:char * ---- c#:StringBuilder//传出参数
    
   //c++:char *变量名 ---- c#:ref string 变量名
    
   //c++:char *输入变量名 ---- c#:string 输入变量名
    
   //c++:char *输出变量名 ---- c#:[MarshalAs(UnmanagedType.LPStr)] StringBuilder 输出变量名
    
   //c++:SHORT(short) ---- c#:System.Int16 
    
   //c++:LONG(long) ---- c#:Syst

全部评论 (0)

还没有任何评论哟~