|
-
Nov 27th, 2001, 12:16 PM
#1
Thread Starter
Lively Member
How Can I Define C functions to use VB Callback
How do i define functions in C so that vb is able to pass through a function address (using the AddressOf function in VB6) adn then what whould be the code in C to call that function address
thanks in advance
-
Nov 28th, 2001, 08:47 AM
#2
a VB funciton that should be called must be declared in the main module:
Code:
public function MyCallback(i as Long, j as Long) as Long
can be passed to a function in C as follows:
PHP Code:
// define the type of the function
typedef long (__stdcall* VBCB)(long, long);
// then the function that receives the address:
void __stdcall Func(long i, VBCB pVbFunc)
{
// call the function
long j = pVbFunc(i, i+1);
}
and the remaining Vb code:
Code:
private declare sub Func lib "thedll" (i as long, pFunc as long)
'call it
Func 34 AddressOf(MyCallback)
'maybe you need to add "" to the function name
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.
-
Nov 28th, 2001, 04:23 PM
#3
MISTAKE!!!
Code:
public function MyCallback(i as Long, j as Long) as Long
'needs to be
public function MyCallback(byval i as Long, byval j as Long) as Long
or you end up with vb.exe producing an access violation 
Code:
private declare sub Func lib "thedll" (i as long, pFunc as long)
'needs to be
private declare sub Func lib "thedll" (byval i as long, byval pFunc as long)
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.
-
Nov 29th, 2001, 04:39 AM
#4
Thread Starter
Lively Member
Thanks....
Thanks for that. It works great
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
|