Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#项目中使用C DLL 我在C++项目中为ATM读卡器做了一个项目,它工作得很好。当我试图在C#项目中使用相同的头文件和DLL时,我不断遇到以下错误: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.'_C#_C++_Dll - Fatal编程技术网

在C#项目中使用C DLL 我在C++项目中为ATM读卡器做了一个项目,它工作得很好。当我试图在C#项目中使用相同的头文件和DLL时,我不断遇到以下错误: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.'

在C#项目中使用C DLL 我在C++项目中为ATM读卡器做了一个项目,它工作得很好。当我试图在C#项目中使用相同的头文件和DLL时,我不断遇到以下错误: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.',c#,c++,dll,C#,C++,Dll,C++代码 10:16:37 COM1´ٍ؟ھ³ة¹¦ handleport=CommOpenWithBaut(119600); 如果(端口==0) { CR你的C++代码调用 CarderCheckSt ,然后是代码> MaGueRe>代码>,但是你的C版本反序调用它们。你的外部声明都是错误的。无符号char和< /C> >应该转换为 REF Byth(假设C++ char被编译为无符号8位整数)。它将字符值解释为地址。与MagRead@madreflection的最后一个参数相同,我

C++代码

10:16:37    COM1´ٍ؟ھ³ة¹¦
handleport=CommOpenWithBaut(119600);
如果(端口==0)
{

CR你的C++代码调用<代码> CarderCheckSt <代码>,然后是代码> MaGueRe>代码>,但是你的C版本反序调用它们。你的外部声明都是错误的。<代码>无符号char和< /C> >应该转换为<代码> REF Byth<代码>(假设C++ char被编译为无符号8位整数)。它将字符值解释为地址。与
MagRead
@madreflection的最后一个参数相同,我相信这不是问题所在。异常在这里抛出
Handle port=CommOpenWithBaut(1,9600)
从一开始就应该包含这些很好的信息。无论如何,我并不是说修复这些问题可以修复您报告的错误,但它们最终仍需要修复。@是的,这是一个问题,因为我不知道C和C中的确切声明。您能帮我参考一下检查这些错误吗
MagRead
的ose参考?
10:16:37    COM1´ٍ؟ھ³ة¹¦
        [DllImport("F:\\ajm\\Components\\ATM\\New folder (2)\\ATMDev\\ATMCsharp\\inc\\ModuleV188.dll", EntryPoint = "CommOpenWithBaut")]
        public static extern IntPtr CommOpenWithBaut(uint nPort, uint _data);

        [DllImport("F:\\ajm\\Components\\ATM\\New folder (2)\\ATMDev\\ATMCsharp\\inc\\ModuleV188.dll", EntryPoint = "CommClose")]
        public static extern int CommClose(IntPtr hComHandle);

        [DllImport("F:\\ajm\\Components\\ATM\\New folder (2)\\ATMDev\\ATMCsharp\\inc\\ModuleV188.dll", EntryPoint = "MagRead")]
        public static extern int MagRead(IntPtr hComHandle, byte[] MagData, ref byte lenth);

        [DllImport("F:\\ajm\\Components\\ATM\\New folder (2)\\ATMDev\\ATMCsharp\\inc\\ModuleV188.dll", EntryPoint = "MagRead")]
        public static extern int CarderCheckSt(IntPtr hComHandle, ref byte PewSt, ref byte CardType, ref byte CardSt, ref byte PowerSt);

        public Form1()
        {
            InitializeComponent();
        }

        public void button1_Click(object sender, EventArgs e)
        {

            IntPtr port = CommOpenWithBaut(1, 9600);

            Byte[] MagData = {128};

            byte lenth = 128;

            byte PewSt = 0 ;
            byte CardType = 0;
            byte CardSt = 0;
            byte PowerSt = 0;

           // CarderCheckSt(port, ref PewSt, ref CardType, ref CardSt, ref PowerSt);


            MagRead(port, MagData, ref lenth);


            MessageBox.Show($"rc");
            MessageBox.Show($"read");


            CommClose(port);

        }