|
-
Dec 18th, 2002, 04:55 PM
#1
Thread Starter
Fanatic Member
C++ DLL calling callback function in VB
is it possible for VB to send a function pointer to a C++ DLL and have the DLL call that function?
the VB function is in a standard module and i used this typedef in C++
typedef void (__stdcall *FUNC_PTR)(long);
and i suppose it passes the value right but when i call the function like this
(*callback)(i);
where i have this in the DLL function arguement list
FUNC_PTR callback
is gives one of those illegal operation errors from windows
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Dec 18th, 2002, 05:15 PM
#2
Make sure the VB function is declared as
Public Sub SomeFunc(ByVal param As Long)
'...
End Sub
and you pass it using AdressOf
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 18th, 2002, 05:20 PM
#3
Thread Starter
Fanatic Member
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Dec 18th, 2002, 06:51 PM
#4
Hyperactive Member
It is very difficult to do the programming in VB (i.e. setting the AddressOf parameters properly, etc.). Make sure that it is correct.
-
Dec 18th, 2002, 06:54 PM
#5
Thread Starter
Fanatic Member
setting addressof parameters? isn't there only one parameter? and thats to a function i wrote in a module
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Dec 19th, 2002, 02:45 AM
#6
The callback worked for me by using your typedef and writing:
VB Code:
Declare Function MyFunc Lib "mylib.dll" (ByVal addrCallback As Long)
Public Sub CB(ByVal l As Long)
Debug.print Format(l)
End Sub
' In a function
MyFunc(AddressOf(CB))
Code:
typedef void (__stdcall *CBFUNC)(long);
void __stdcall MyFunc(CBFUNC f)
{
f(5);
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|