Any ideas on how to use the WIP library with C++ ??
extern "C"
{
#include "adl_global.h"
#include "wip.h"
class myClass
{
public:
void thing(void){
int a =WIP_CEV_OPEN; //Problem description: Symbol 'WIP_CEV_OPEN' could not be resolved
}
private:
}
Seems to be related to the fact that WIP_CEV_OPEN enum definition is enclosed in wip_event_t structure definition (cf. wip_channel.h)
To use this constant in C++, you’ll need to reference it as:
As ADL or WIP are written in C, you have to provide C callbacks… AFAIK there is no way to provide class methods (even static ones) as callbacks to a C API…
You’ll have to implement the callback in an extern “C” block of a cpp file.
Thanks for the information - as you can probably tell I’m not used to mixing C and C++.
I now understand - I think this C++ limitation means that it’s impossible to build a proper class which wrappers C which uses callbacks.
Shame - I was hoping to save a lot of time by creating a C++ WIP interface to enable many identical socket objects - never mind I’ll have to go back to the old C way
I think that you can do it anyhow: most (and even maybe all) of the WIP callbacks can bear an opaque “context” pointer.
You should be able to use one single generic C callback for all your instances, and use the context pointer to carry your current object instance.
Thanks - yes from a C perspective the context method works well.
I don’t think a WIP context could point to a C++ class member - I’m not sure of any other methods I could use to connect a WIP context to a C++ class member
Just be aware that with timer contexts that if you cancel the timer (and thus don’t call the handler), there is no way to free the context if you don’t keep another link to it somewhere (which in my view sort of defeats the purpose of a context pointer) - so you will get a memory leak.
It would be nice if there was some sort of timer finalizer that could be called if the timer was cancelled…