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
Printable View
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
a VB funciton that should be called must be declared in the main module:
can be passed to a function in C as follows:Code:public function MyCallback(i as Long, j as Long) as Long
and the remaining Vb code: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);
}
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
MISTAKE!!!
or you end up with vb.exe producing an access violation :)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
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)
Thanks for that. It works great