[英]Call a DLL with 'pointer' and structure (C++ -> VB.NET)
I have problem about how I call a function on DLL to get data from a structure ... 我对如何在DLL上调用函数以从结构中获取数据有疑问...
Have a C++ example about how it's works the library, and I want to use it on vb.net 有一个有关库如何工作的C ++示例,我想在vb.net上使用它
Okay, this is the working c++ example: 好的,这是有效的c ++示例:
Declaration: 宣言:
BOOL (WINAPIV* MyFun)(DWORD start1, DWORD stop1, P_RESULT pResult, PDWORD pTpNum, myCALLBACK lpFunc) = NULL;
Call: 呼叫:
// pStruc = RESULT structure
// TrpNum1, TrpNum is ULONG
ULONG TrpNum1=0;
MyFun(Start,Stop,pStruc+TrpNum,&TrpNum1,&myCB);
Callback: 打回来:
void __stdcall myCB (RESULT *pStruc)
{
printf ("%.3f", (double)pStruc->val1);
tpn++;
}
And of course, the structure: 当然,结构为:
typedef struct {
BOOL mybool;
DWORD val1;
DWORD val2;
} RESULT, *P_RESULT;
And this is my VB.net code (not working): 这是我的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
Structure: 结构体:
Public Structure RESULT
Dim mybool As Boolean
Dim val1 As UInt32
Dim val2 As UInt32
End Structure
What is wrong guys? 谁错了?
Thanks in advance. 提前致谢。
Edit: The error is this: "Attempted to read or write protected memory. This often indicates that other memory is corrupt." 编辑:错误是这样的:“试图读取或写入受保护的内存。这通常表明其他内存已损坏。”
Also i do a small 'fix' in the code. 我也在代码中做了一个小的“修正”。 Still don't work. 还是不行。
There are a large number of problems here: 这里有很多问题:
You need help to get this going, help that's a bit beyond with SO can provide. 您需要帮助才能做到这一点,SO所不能提供的帮助。 Ask an experienced team member for assistance or hire a consultant. 向经验丰富的团队成员寻求帮助或聘请顾问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.