You can share objects in a shared section, but you have to be sneaky to do it by using placement new:
Code:
#pragma comment(linker, "/SECTION:.SHARED,RWS")
#pragma data_seg(".SHARED")
HHOOK hHookCbt = 0;
static BYTE buffer[sizeof(Handler)] = {0};
#pragma data_seg()
// each process gets its own copy of the pointer:
static Handler* pHandler = NULL;
...
// In the first process to load the dll, create the single shared handler using placement new:
pHandler = new (buffer) Handler;
// subsequent processes just cast the pointer:
pHandler = reinterpret_cast<Handler*>(buffer);
The destructor won't get called automatically using this mechanism, so if you need it to run, call it explicitly when the last process exits:
Code:
pHandler->~Handler();
Ian