尝试设置USB电源板.
这是文档:
Initializes the Power USB API.
Name: InitPowerUSB
Parameters: model:returns the model number(1:basic, 2:digIO, 3:watchdog, 4:Smart), firmware: returns firmware version in ?.? format in a character string (major revision and minor revision)
Return: >0 if successful. Returns number of PowerUSB devices connected
C++ Example:
if (!m_pwrUSBInit)
{
int model; char firmware[8];
if ((ret=InitPowerUSB(&model, firmware)) > 0)
{
m_pwrUSBInit = 1;
m_numDevices = ret;
}
}
Run Code Online (Sandbox Code Playgroud)
我一直试图用我的VB6代码工作大约一个小时,现在没有运气.该程序或者崩溃,显示这样的错误Bad Calling Dll Convention
,type mismatch
,等等.
这就是我所拥有的:
Public Declare Function InitPowerUSB Lib "PwrUSBDll.dll" (ByRef model As Integer, ByVal firmware As String) As Integer
Dim model As Integer
model = 0
Dim firmware As String
firmware = ""
If (InitPowerUSB(model, firmware)) > 0) Then
EndIf
Run Code Online (Sandbox Code Playgroud)
我已经尝试将固件更改为字节数组,byref,字符串,整数,长整数等.它似乎并不想运行.
有谁知道这个问题的解决方案?谢谢
我无法回答你剩下的功能签名问题因为我没有你的任何文档PwrUSBDll.dll
.
但是,"错误的DLL调用约定"错误通常意味着您有一个CDecl
入口点,VB6只能在有一些帮助的情况下调用它们.
有几个修复.
显而易见的是修改源代码并使用StdCall
而不是重新编译该DLL .
另一种方法是为该DLL创建一个类型库,这有助于向VB6通知该问题并解决它.
然后你可以选择使用VB6的无证CDecl装饰器:
Public Declare Function InitPowerUSB CDecl Lib "PwrUSBDll.dll" ( _
ByRef model As Integer, _
ByVal firmware As String) As Integer
Run Code Online (Sandbox Code Playgroud)
然而,缺点是在IDE中运行时不起作用,在编译为p代码时也不起作用.p代码解释器不处理此关键字.
因此,您可以在IDE运行中绕过它并提供虚拟结果进行测试,或者您可以在VB6中创建一个小包装DLL,您可以单独编译为本机代码.
注意事项:
为了解决您的问题,我们必须假设您在该参数列表中传递了正确的数据类型.C++ int
是VB6 Long
.除非这是一个Unicode DLL入口点,否则最好不要传递VB6 Byte
数组.函数返回值也是最有可能的.ByRef
char[8]
Long