Friday, 26 October 2012

access c++ class from main / c / callback function

Non-member functions do not have access to to "this"
pointer of your class.

You need to do the following :

1) create a GLOBAL pointer to your class. So near the
top of the CPP file, add something like :

CYourClass pYourClass = NULL;




2) sometime before the callback function is to
be called, you need to initialize the pointer. This
must be done in a member function of your class :

pYourClass = this;




3) then in the callback function :

if (pYourClass != NULL)
pYourClass->Whatever();