> > BTW, you have considered prosen's suggestion for creating a
> scope guard,
> > haven't you? It's a bright suggestion.
>
> It won't work in my situation as it stands - remember, it
> relies on the
> methods accessing the protected object being members of a
> class, and having
> a CCriticalSection as a member of that same class; one of the
> places I need
> to access the item is from within a worker thread proc, which
> is not part of
> any class (the first form of AfxBeginThread() as shown in
> MSDN). Thus, no
> member variables.
Here's a little trick I always use for call back functions:
The call back function always allows a parameter to be passed to it.
Make that parameter the pointer to a class, then use that pointer to get
to a member function of that class. Therefore, even though the callback
function has to be static, it immediately calls a non-static function,
then you're free to use member variables.
That is:
class CMyClass
{
static void CallBack(void* pThis)
{
((CMyClass*)pThis)->MemberCallBack();
}
void MemberCallBack();
};