
CALLBACK Functions as Class Members
The typical way to do it would be:
class CFoo
{
public:
static void RawCallback( int nFoo, LONG lUserData );
{
CFoo* pFoo = reinterpret_cast<CFoo*>( lUserData );
pFoo->Callback( nFoo );
}
void Callback( int nFoo )
{
... blah blah blah ...
}
Quote:
};
Do you mean that the API you're using has no provision for an "lUserData"
argument that it retains and passes to your callback? If so, then the best
tactic depends on whether you have one CFoo object or many.
If one CFoo, just store it in some global variable g_pFoo.
class CFoo
{
...
static void RawCallback( int nFoo, LONG lUserData );
{
g_pFoo->Callback( nFoo );
}
If many CFoo objects, then RawCallback() must have _some_ argument to let
you determine the appropriate CFoo to use. (If not, the API or your
approach to using it with CFoo is flawed). For instance, maybe it has a
"WORD wUserData" arugment, not big enough to hold a real CFoo*. In that
case, try using a CDict< WORD, CFoo* > to lookup the appropriate CFoo*
given the WORD id. Basically that's how MFC associates CWnd*s with HWNDs.
Greg