C# System.EntryPointNotFoundException:找不到入口点
我已经将VB6转换为c#并在执行时生成此错误 来自VB6C# System.EntryPointNotFoundException:找不到入口点,c#,vb6,C#,Vb6,我已经将VB6转换为c#并在执行时生成此错误 来自VB6 Declare Function OpenCommPort Lib "C:\Program Files\MR705API.dll" Alias "?OpenCommPort@@YGHPADPAPAX@Z" (ByVal PortName As String, ByRef hCom As Long) As Long Declare Function CloseCommPort Lib "C:\Program Files\MR705API.d
Declare Function OpenCommPort Lib "C:\Program Files\MR705API.dll" Alias "?OpenCommPort@@YGHPADPAPAX@Z" (ByVal PortName As String, ByRef hCom As Long) As Long
Declare Function CloseCommPort Lib "C:\Program Files\MR705API.dll" Alias "?CloseCommPort@@YGHPAX@Z" (ByVal hCom As Long) As Long
Declare Function SetLED Lib "C:\Program Files\MR705API.dll" Alias "?SetLED@@YGHPAXEE@Z" (ByVal hCom As Long, ByVal Led As Byte, ByVal Addr As Byte) As Long
Declare Function ActiveBuzzer Lib "C:\Program Files\MR705API.dll" Alias "?ActiveBuzzer@@YGHPAXEE@Z" (ByVal hCom As Long, ByVal DelayTime As Byte, ByVal Addr As Byte) As Long
Declare Function Iso14443Reqa Lib "C:\Program Files\MR705API.dll" Alias "?Iso14443Reqa@@YGHPAXEPAEE@Z" (ByVal hCom As Long, ByVal ReqAMode As Byte, ByVal ATQ As String, ByVal Addr As Byte) As Long
Declare Function Iso14443Anticoll Lib "C:\Program Files\MR705API.dll" Alias "?Iso14443Anticoll@@YGHPAXEPAE1E@Z" (ByVal hCom As Long, ByVal AnticollMode As Byte, ByVal Uid As String, ByVal MultiTag As String, ByVal Addr As Byte) As Long
用C#
以及我如何使用它。
public void doReader() {
Result = OpenCommPort("COM9", ref HANDLE);
....
....
}
例外情况
System.EntryPointNotFoundException: Unable to find an entry point named 'OpenCommPort' in DLL 'MR705API.dll'.
at TrueReader.MainForm.OpenCommPort(String portName, Int64& hCom)
at TrueReader.MainForm.doReader() in c:\Users\sattha\Documents\SharpDevelop Projects\TrueReader\TrueReader\MainForm.cs:line 59
at TrueReader.MainForm.Timer1Tick(Object sender, EventArgs e) in c:\Users\sattha\Documents\SharpDevelop Projects\TrueReader\TrueReader\MainForm.cs:line 54
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TrueReader.Program.Main(String[] args) in c:\Users\sattha\Documents\SharpDevelop Projects\TrueReader\TrueReader\Program.cs:line 27
谁能指引我,我做错了什么??或者我错过了什么
我不知道这个.dll是怎么写的,用哪种语言写的
但它以前在VB6中使用过
您应该为每个DLLIMPORT函数定义入口点
只需将入口点从Alias
从VB6代码复制到C#
例如。。。VB6中的“OpenCommPort”
Declare Function OpenCommPort Lib "C:\Program Files\MR705API.dll" Alias "?OpenCommPort@@YGHPADPAPAX@Z" (ByVal PortName As String, ByRef hCom As Long) As Long
Declare Function CloseCommPort Lib "C:\Program Files\MR705API.dll" Alias "?CloseCommPort@@YGHPAX@Z" (ByVal hCom As Long) As Long
Declare Function SetLED Lib "C:\Program Files\MR705API.dll" Alias "?SetLED@@YGHPAXEE@Z" (ByVal hCom As Long, ByVal Led As Byte, ByVal Addr As Byte) As Long
Declare Function ActiveBuzzer Lib "C:\Program Files\MR705API.dll" Alias "?ActiveBuzzer@@YGHPAXEE@Z" (ByVal hCom As Long, ByVal DelayTime As Byte, ByVal Addr As Byte) As Long
Declare Function Iso14443Reqa Lib "C:\Program Files\MR705API.dll" Alias "?Iso14443Reqa@@YGHPAXEPAEE@Z" (ByVal hCom As Long, ByVal ReqAMode As Byte, ByVal ATQ As String, ByVal Addr As Byte) As Long
Declare Function Iso14443Anticoll Lib "C:\Program Files\MR705API.dll" Alias "?Iso14443Anticoll@@YGHPAXEPAE1E@Z" (ByVal hCom As Long, ByVal AnticollMode As Byte, ByVal Uid As String, ByVal MultiTag As String, ByVal Addr As Byte) As Long
别名“?OpenCommPort”@@YGHPADPAPAX@Z"
到->C#中的“OpenCommPort”
附加的
long
inVB6相当于int
inC#在VB6中的long相当于.NET中的In32,因此您的pinvoke是错误的。如果它找不到与错误信号匹配的信号,则该错误将被忽略result@Plutonix你的意思是我必须从long更改为int32?@PUROTIX它无论如何都不起作用是的,这就是我所指的。@JongzPuangput“system.accessviolationexception试图读取或写入受保护内存”-通常表示p-invoke declarion不正确。e、 g.不正确的int
长度;缺少输出
参数
;指针;等等
[DllImport ("MR705API.dll",
EntryPoint="?OpenCommPort@@YGHPADPAPAX@Z")]
public static extern int OpenCommPort(string portName, ref int hCom);