Anonymous wrote:
I have legacy C code that performs some required functionality. I want
to notify my C++ classes after work has been completed in the C code.
In otherwords, I need to call a C++ method from C.
Some PSEUDO code may help:
/* C++ code */
class MyFooClass
{
public:
NotifyHandler();
};
/* C code */
#ifdef __cplusplus
extern "C" {
#endif
void foo()
{
/* Do some work */
/* finish work */
/* Notify C++ class via callback here */
}
#ifdef __cplusplus
};
#endif
First off, there is some information on callbacks in the FAQ,
have you read it? If not, please do.
Second, the simplest way is to compile your so called C code
as C++ and be done with it, then you can pass your object in
and call anything you want from it.
If that's not something you want or are prepared to do, you
could play the static_cast game, where your class has a static
member function with a 'void*' argument. Inside it casts the
pointer to an object of its type ('MyFooClass') and calls the
member function. The C will need a void* passed to it so it
can pass it "back" to the static function.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask