Annotation of parser3/src/sql/odbc/MFCpatches/WINHAND_.H, revision 1.1
1.1 ! parser 1: // This is a part of the Microsoft Foundation Classes C++ library.
! 2: // Copyright (C) 1992-1998 Microsoft Corporation
! 3: // All rights reserved.
! 4: //
! 5: // This source code is only intended as a supplement to the
! 6: // Microsoft Foundation Classes Reference and related
! 7: // electronic documentation provided with the library.
! 8: // See these sources for detailed information regarding the
! 9: // Microsoft Foundation Classes product.
! 10:
! 11: /////////////////////////////////////////////////////////////////////////////
! 12: // CHandleMap
! 13: //
! 14: // Note: Do not access the members of this class directly.
! 15: // Use CWnd::FromHandle, CDC::FromHandle, etc.
! 16: // The actual definition is only included because it is
! 17: // necessary for the definition of CWinThread.
! 18: //
! 19: // Most Windows objects are represented with a HANDLE, including
! 20: // the most important ones, HWND, HDC, HPEN, HFONT etc.
! 21: // We want C++ objects to wrap these handle based objects whenever we can.
! 22: // Since Windows objects can be created outside of C++ (eg: calling
! 23: // ::CreateWindow will return an HWND with no C++ wrapper) we must
! 24: // support a reasonably uniform mapping from permanent handles
! 25: // (i.e. the ones allocated in C++) and temporary handles (i.e.
! 26: // the ones allocated in C, but passed through a C++ interface.
! 27: // We keep two dictionaries for this purpose. The permanent dictionary
! 28: // stores those C++ objects that have been explicitly created by
! 29: // the developer. The C++ constructor for the wrapper class will
! 30: // insert the mapping into the permanent dictionary and the C++
! 31: // destructor will remove it and possibly free up the associated
! 32: // Windows object.
! 33: // When a handle passes through a C++ interface that doesn't exist in
! 34: // the permanent dictionary, we allocate a temporary wrapping object
! 35: // and store that mapping into the temporary dictionary.
! 36: // At idle time the temporary wrapping objects are flushed (since you better
! 37: // not be holding onto something you didn't create).
! 38: //
! 39:
! 40: class CWinThread; // forward reference for friend declaration
! 41:
! 42: class CHandleMap
! 43: {
! 44: private: // implementation
! 45: CMapPtrToPtr m_permanentMap;
! 46: CMapPtrToPtr m_temporaryMap;
! 47: CRuntimeClass* m_pClass;
! 48: size_t m_nOffset; // offset of handles in the object
! 49: int m_nHandles; // 1 or 2 (for CDC)
! 50:
! 51: // Constructor/Destructor
! 52: public:
! 53: CHandleMap(CRuntimeClass* pClass, size_t nOffset, int nHandles = 1);
! 54: #ifdef _AFXDLL
! 55: ~CHandleMap()
! 56: #else
! 57: virtual ~CHandleMap()
! 58: #endif
! 59: { DeleteTemp(); }
! 60:
! 61: // Operations
! 62: public:
! 63: CObject* FromHandle(HANDLE h);
! 64: void DeleteTemp();
! 65:
! 66: void SetPermanent(HANDLE h, CObject* permOb);
! 67: void RemoveHandle(HANDLE h);
! 68:
! 69: CObject* LookupPermanent(HANDLE h);
! 70: CObject* LookupTemporary(HANDLE h);
! 71:
! 72:
! 73: friend class CWinThread;
! 74: };
! 75:
! 76: // Note: out-of-line _DEBUG version is in winhand.cpp
! 77: #ifndef _DEBUG
! 78: inline void CHandleMap::SetPermanent(HANDLE h, CObject* permOb)
! 79: { m_permanentMap[(LPVOID)h] = permOb; }
! 80:
! 81: inline void CHandleMap::RemoveHandle(HANDLE h)
! 82: {
! 83: // remove only from permanent map -- temporary objects are removed
! 84: // at idle in CHandleMap::DeleteTemp, always!
! 85: m_permanentMap.RemoveKey((LPVOID)h);
! 86: }
! 87: #endif
! 88:
! 89: inline CObject* CHandleMap::LookupPermanent(HANDLE h)
! 90: { return (CObject*)m_permanentMap.GetValueAt((LPVOID)h); }
! 91: inline CObject* CHandleMap::LookupTemporary(HANDLE h)
! 92: { return (CObject*)m_temporaryMap.GetValueAt((LPVOID)h); }
E-mail: