I have code that looks like this:
extern "C" __declspec(dllexport) myInterface(int id, void** pFunction)
{
...
}
I need to make the void** pFunction argument point to a function so that the caller can use this function via the pFunction pointer. This function gets called through a DLL, I don’t want to do it this way but for a lot of reasons I have no choice. I know that COM is made for this but I can not use it, the reasons come down to management.
At this point I have no idea how to do this, everything I have tried to do gives me cast problems. Do anyone have any idea how I can do this? I can post more if this is unclear.
Thanks.
As Jonathan Leffler and David Thornley mentioned, you aren’t guaranteed that a function pointer can be converted to
void*and back. A portable workaround would be to package the function pointer into astructand to pass a pointer to that.(Be aware that
void**itself might have its own issues. You can avoid this too.)For example:
and then myInterface could be implemented as: