this looks great, but Im having trouble compiling with it - I get C2501 'missing storage class or type specifiers' for each of the 'CSemaphore *m_pSync' and 'CSingleLock *m_pLock' declarations in SharedMemory.h (and it goes downhill from there)
My guess would be that I need to tell MFC to include Multithreaded support (I would likely do the same if I was on my other dev platform, Sun Solaris) .. but Im not sure what this means on MFC ...
sorry, thats probably a real basic question, maybe by the time Ive spent some time tomorrow (Saturday) on it, I'll have the answer myself ... (just need some backup/reassurance )
ps ... (1) #include <afxmt.h> was gleaned from a quick web-scan .. I'll post back here when Ive tried it - one of the problems with where I live is, its GMT +10. This is well ahead of most of you in the USA, so I like to try and get questions out there early, so as maybe by the next day I'll have answers ...
Thanks for a great job in the classes, Im learning a lot here ..
It's great that you have a callback in your constructor to initialize the memory at allocation time. You might want to make this callback more C++ friendly either by adding a "user parameter" (an opaque void *) that is passed to the callback. That way, if my CFoo class is creating the shared memory, I can do this:
CSharedMemory* pNewBlock = new CSharedMemory("name", 1024, CFoo::Initializer, this);
/*static*/void CFoo::Initializeer(CSharedMemory* pMem, void* p)
CFoo* This = (CFoo*) p;
// "This" now has access to my CFoo object
Alternatively, if you want to go the "real" OO C++ route, you can make the callback a functor.
Martin Ziacek wrote: It is a lovely idea to pass one more parameter to callback function, however it has nothing to do with C++ at all.
Actually, it is a C++ issue, because it's the only way to get a C-style callback to call an object method (as opposed to a standalong function or a static method).
It seems like a minor thing, until you run across one of the few callbacks in the Windows API (SetTimer) that doesn't let you pass a user parameter, and you have to resort to hackery to get an object method called in response to it.
Last Visit: 31-Dec-99 18:00 Last Update: 8-Mar-14 13:56