c#调用c++生成的dll库文件报错的处理:对 PInvoke 函数“CallCPlusPlusDLL!CallCPlusPlusDLL.Program::Min”的调用导致堆栈不对称
把引用DllImport()函数里添加参数
如:把[DllImport("dllDemo.dll")] 改为[DllImport("dllDemo.dll", CallingConvention = CallingConvention.Cdecl)]即可
更正后具体代码如下:
View Code 
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Runtime.InteropServices; 6 7 namespace CallCPlusPlusDLL 8 { 9 class Program 10 { 11 ////引入dll中的函数 12 [DllImport("dllDemo.dll", CallingConvention = CallingConvention.Cdecl)] 13 private static extern int Sum(Int32 a, Int32 b); 14 [DllImport("dllDemo.dll", CallingConvention = CallingConvention.Cdecl)] 15 private static extern int Max(Int32 a, Int32 b); 16 [DllImport("dllDemo.dll", CallingConvention = CallingConvention.Cdecl)] 17 private static extern int Min(Int32 a, Int32 b); 18 19 static void Main(string[] args) 20 { 21 Int32 resSum = Sum(5, 8); 22 Console.WriteLine(resSum); 23 Int32 resMax = Max(5, 8); 24 Console.WriteLine(resMax); 25 Int32 resMin = Min(5, 8); 26 Console.WriteLine(resMin); 27 Console.ReadKey(); 28 29 } 30 31 } 32 }
                    
                

                
            
        
浙公网安备 33010602011771号