0
我在執行它產生這個錯誤System.EntryPointNotFoundException:無法找到一個切入點
從VB6
Declare Function OpenCommPort Lib "C:\Program Files\MR705API.dll" Alias "[email protected]@[email protected]" (ByVal PortName As String, ByRef hCom As Long) As Long
Declare Function CloseCommPort Lib "C:\Program Files\MR705API.dll" Alias "[email protected]@[email protected]" (ByVal hCom As Long) As Long
Declare Function SetLED Lib "C:\Program Files\MR705API.dll" Alias "[email protected]@[email protected]" (ByVal hCom As Long, ByVal Led As Byte, ByVal Addr As Byte) As Long
Declare Function ActiveBuzzer Lib "C:\Program Files\MR705API.dll" Alias "[email protected]@[email protected]" (ByVal hCom As Long, ByVal DelayTime As Byte, ByVal Addr As Byte) As Long
Declare Function Iso14443Reqa Lib "C:\Program Files\MR705API.dll" Alias "[email protected]@[email protected]" (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 "[email protected]@[email protected]" (ByVal hCom As Long, ByVal AnticollMode As Byte, ByVal Uid As String, ByVal MultiTag As String, ByVal Addr As Byte) As Long
在C#轉換VB6到C#
[DllImport ("MR705API.dll")]
public static extern long OpenCommPort(String portName, ref long hCom);
[DllImport ("MR705API.dll")]
public static extern long CloseCommPort(long hCom);
[DllImport ("MR705API.dll")]
public static extern long SetLED(long hCom, byte Led , byte Addr);
[DllImport ("MR705API.dll")]
public static extern long ActiveBuzzer (long hcom, byte DelayTime, byte Addr);
[DllImport ("MR705API.dll")]
public static extern long Iso14443Reqa (long hcom, byte ReqAMode, string ATQ, byte Addr);
以及我如何使用它..
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中使用過。
長在VB6將等同於.NET中的In32,所以你的PInvokes是錯誤的。如果找不到錯誤的sig匹配,那麼會導致錯誤 – Plutonix 2014-10-30 23:57:04
@Plutonix你的意思是我必須從long更改爲int32? – 2014-10-30 23:57:51
@Plutonix它無法正常工作 – 2014-10-31 00:03:49