我对如何调用 DLL 上的函数以从结构中获取数据有疑问...
有一个关于它是如何工作的库的 C++ 示例,我想在 vb.net 上使用它
好的,这是有效的 C++ 示例:
宣言:
BOOL (WINAPIV* MyFun)(DWORD start1, DWORD stop1, P_RESULT pResult, PDWORD pTpNum, myCALLBACK lpFunc) = NULL;
称呼:
// pStruc = RESULT structure
// TrpNum1, TrpNum is ULONG
ULONG TrpNum1=0;
MyFun(Start,Stop,pStruc+TrpNum,&TrpNum1,&myCB);
打回来:
void __stdcall myCB (RESULT *pStruc)
{
printf ("%.3f", (double)pStruc->val1);
tpn++;
}
当然,结构:
typedef struct {
BOOL mybool;
DWORD val1;
DWORD val2;
} RESULT, *P_RESULT;
这是我的 VB.net 代码(不工作):
Public Declare Auto Function MyFun Lib "\mydll.dll" ( _
ByVal start As UInt32, _
ByVal stop As UInt32, _
ByRef Result As RESULT, ByRef pTpNum As UInt32, ByVal lpFunc As DlgCB) As Boolean
Public Sub CallMyFun()
Dim Res As New RESULT
Dim TpN As UInt32
If MyFun(100, 200, Res, TpN, AddressOf myCB) Then
SendDebug("OK")
Else
SendDebug("Failed!")
End If
End Sub
Public Delegate Function DlgCB(ByVal Res As RESULT) As Boolean
Public Function myCB(ByVal Res As RESULT) As Boolean
Debug.Print(Res.val1)
Return True
End Function
结构:
Public Structure RESULT
Dim mybool As Boolean
Dim val1 As UInt32
Dim val2 As UInt32
End Structure
什么是错的家伙?
提前致谢。
编辑:错误是这样的:“试图读取或写入受保护的内存。这通常表明其他内存已损坏。”
我也在代码中做了一个小的“修复”。还是不行。