我试图让我的VB.NET 2017 Windows窗体GUI调用由Inheco.com公司提供的DLL(InhecoMTCDLL.dll)中的函数。 Inheco说DLL使用C#app确定,但是示例C#程序不可用,并且没有DLL的源代码。他们说他们只支持C#而不支持VB。 我的应用程序是用VB.NET编写的。
VB& DLL属性
dotPeek reports that DLL is:
x86 .NET Framework 3.5
My VB.NET app is:
Target CPU is: x86
.NET Framework 4.5.1 (build fails for 3.5)
VB.NET DECLARATION ----------我的VB.NET声明是这样的:
Imports System.Runtime.InteropServices
Module Thermoshake_Interface
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DLL INTERFACE DECLARATIONS...
' Function within DLL:
' Public int FindTheUniversalControl(int ID);
' which corresponds to VB.NET declaration:
<DllImport("InhecoMTCdll.dll")>
Public Function FindTheUniversalControl(byval ID As Int32) As Int32
End Function
End Module
VB调用DLL -----------而且,我的应用程序调用DLL中的函数是这样的:
Private Sub Button_test_Thermoshake_DLL_Click(sender As Object, e As EventArgs) Handles Button_test_Thermoshake_DLL.Click
Stop ' and test!!!
Dim Thermoshake_controller_ID_int32 as int32 = 0
Dim return_status As Int32
return_status = Thermoshake_Interface.FindTheUniversalControl( Thermoshake_controller_ID_int32 )
TextBox_Thermoshake_communication.Text &= "FindTheUniversalControl(0) returned " & return_status
End Sub
E R R O R ------------我得到的错误是:
"Unable to find an entry point named 'FindTheUniversalControl' in DLL 'InhecoMTCdll.dll'.":""} System.EntryPointNotFoundException
D U M P B I N -----------下面的dumpbin输出显示没有导出的函数。 DLL源代码不可用。然而,dotPeek反编译它,我看到了'FindTheUniversalControl&#39;那里,但我不是dotPeek出口:
C:\PRIMARY\MUSE_BIO\WORK\SYSTEM GUI V1>dumpbin inhecomtcdll.dll /exports
Microsoft (R) COFF/PE Dumper Version 14.10.25019.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file inhecomtcdll.dll
File Type: DLL
Summary
2000 .reloc
2000 .rsrc
6000 .text
D o t P e e k ------ dotPeek反编译函数及其类:
// Decompiled with JetBrains decompiler
// Type: InhecoMTCdll.GlobCom
// Assembly: InhecoMTCdll, Version=1.2.7.0, Culture=neutral, PublicKeyToken=null
// MVID: 054E16B0-4E1E-48C4-B9BF-9443EECE4E3D
// Assembly location: C:\PRIMARY\me\WORK\Thermoshake DLL project\InhecoMTCdll.dll
using HID_Test_Application;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Timers;
namespace InhecoMTCdll
{
[ComSourceInterfaces(typeof (InhecoMTCEvents))]
[ClassInterface(ClassInterfaceType.None)]
[Guid("0CEE0396-3016-41db-B914-0C94132DEA8B")]
public class GlobCom : InhecoMTCInterface
{
private Hid _TTHID = new Hid();
private DeviceManagement _MyDeviceManagement = new DeviceManagement();
public System.Timers.Timer timerTimeout = new System.Timers.Timer();
private WaitHandle[] waithandleTT = new WaitHandle[3];
private IntPtr _DeviceNotificationHandle;
public int _HIDHandle;
public int _ReadHandle;
public int _WriteHandle;
private bool _MyDeviceDetected;
private string _MyDevicePathName;
private string wholeReply;
private bool griechished;
private byte finish;
private int localDeviceID;
public string puStrResult;
private byte crc;
private bool bResend;
private string localMSG;
...
public int FindTheUniversalControl(int ID)
{
Guid empty = Guid.Empty;
HidApiDeclarations.HidD_GetHidGuid(ref empty);
empty.ToString();
string[] devicePathName = new string[128];
int numberOfInputBuffers = 32;
int num1 = 1003;
int num2 = 8227 + ID;
int num3 = 0;
int num4 = 0;
this.localDeviceID = ID;
FileIOApiDeclarations.SECURITY_ATTRIBUTES lpSecurityAttributes = new FileIOApiDeclarations.SECURITY_ATTRIBUTES();
this.timerTimeout.Elapsed += new ElapsedEventHandler(this.timerTimeout_Tick);
if (this._MyDeviceManagement.FindDeviceFromGuid(empty, ref devicePathName))
{
this.timerTimeout.Interval = 500.0;
int index = 0;
do
{
this._HIDHandle = FileIOApiDeclarations.CreateFile(devicePathName[index], 0U, 3U, ref lpSecurityAttributes, 3, 0U, 0);
if (this._HIDHandle != -1)
{
this._TTHID.DeviceAttributes.Size = Marshal.SizeOf((object) this._TTHID.DeviceAttributes);
if (HidApiDeclarations.HidD_GetAttributes(this._HIDHandle, ref this._TTHID.DeviceAttributes) != 0)
{
if ((int) this._TTHID.DeviceAttributes.VendorID == num1 & (int) this._TTHID.DeviceAttributes.ProductID == num2)
{
this._MyDeviceDetected = true;
this._MyDevicePathName = devicePathName[index];
num4 = 1;
}
else
{
this._MyDeviceDetected = false;
num3 = FileIOApiDeclarations.CloseHandle(this._HIDHandle);
num4 = 0;
}
}
else
{
this._MyDeviceDetected = false;
num3 = FileIOApiDeclarations.CloseHandle(this._HIDHandle);
num4 = 0;
}
}
++index;
}
while (!(this._MyDeviceDetected | index == devicePathName.Length));
}
if (this._MyDeviceDetected)
{
bool flag = this._MyDeviceManagement.RegisterForDeviceNotifications(this._MyDevicePathName, empty, ref this._DeviceNotificationHandle);
this._TTHID.Capabilities = this._TTHID.GetDeviceCapabilities(this._HIDHandle);
if (flag)
{
this._TTHID.GetHIDUsage(this._TTHID.Capabilities);
this._TTHID.GetNumberOfInputBuffers(this._HIDHandle, ref numberOfInputBuffers);
this._ReadHandle = FileIOApiDeclarations.CreateFile(this._MyDevicePathName, 2147483648U, 3U, ref lpSecurityAttributes, 3, 1073741824U, 0);
if (this._ReadHandle != -1)
this._WriteHandle = FileIOApiDeclarations.CreateFile(this._MyDevicePathName, 1073741824U, 3U, ref lpSecurityAttributes, 3, 0U, 0);
this._TTHID.FlushQueue(this._ReadHandle);
}
}
return num4;
}