C#DLLImport错误:尝试加载格式不正确的程序。(HRESULT异常:0x8007000B)。 [英] C# DLLImport Error: An attempt was made to load a program with an incorrect format.( Exception from HRESULT: 0x8007000B).
问题描述
当我运行我的程序时它说" 试图加载一个格式不正确的程序。(HRESULT异常:0x8007000B)",当我尝试使用它的功能。这是我的代码:
[ DllImport ( " mxgpio.dll" , CharSet = CharSet 。 Unicode )]
公开 静态 extern IntPtr mxdgio_open ();
[ DllImport ( " mxgpio.dll" , CharSet = CharSet 。 Unicode )]
公开 静态 extern int mxdgio_get_input_signal ( IntPtr fd , int 端口 );
[ DllImport ( " mxgpio.dll" , CharSet = CharSet 。 Unicode )]
公开 静态 extern 无效 mxdgio_close ( IntPtr fd );
现在.dll中的函数是C ++,它们使用Handle但我用IntPtr替换它,因为C#没有Handle,所以也许这就是我遇到这个问题的原因:
IntPtr hDIO = mxdgio_open ();
Murphy_Switch1 = mxdgio_get_input_signal ( hDIO , 0 );
AppendTextBox ( Convert 。 ToString ( Murphy_Switch1 ));
Murphy_Switch2 = mxdgio_get_input_signal ( hDIO , 1 );
AppendTextBox ( Convert 。 ToString ( Murphy_Switch2 ));
Flow_Indicator_Switch = mxdgio_get_input_signal ( hDIO , 2 );
AppendTextBox ( Convert 。 ToString ( Flow_Indicator_Switch ));
程序在第一行失败:
IntPtr hDIO = mxdgio_open();
我检查了3次,所有.dll文件都来自x64文件夹,我的电脑运行64位操作系统
我检查了3次,所有.dlls 都来自x64折,而我的电脑运行的是64位操作系统 解决方案
when I run my program it says " An attempt was made to load a program with an incorrect format.( Exception from HRESULT: 0x8007000B)", when I try to use the functions from it. here is my code :
Now the functions in the .dll are C++ and they use Handle but I replace that with IntPtr because C# does not have Handle, so maybe that is why I am having this problem:
The program fails at that 1st line: IntPtr hDIO = mxdgio_open(); I checked 3 times and all the .dlls files are from the x64 folder and my computer run a 64 bit OS
|