multiutl.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 5k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #ifndef __MULTIUTL_H
  2. #define __MULTIUTL_H
  3. #include <assert.h>
  4. #include "objidl.h"
  5. #include <pstore.h>
  6. #include "multiusr.h"
  7. #ifndef Assert
  8. #ifdef DEBUG
  9. #define Assert(a) assert(a)
  10. #define SideAssert(a) Assert(a)
  11. #define AssertSz(a, sz) Assert(a)
  12. #define ASSERT_MSGA     1 ? (void)0 : (void)
  13. #else // DEBUG
  14. #define ASSERT_MSGA     1 ? (void)0 : (void)
  15. #define Assert(a)
  16. #define SideAssert(a) (a)
  17. #define AssertSz(a, sz) 
  18. #endif // DEBUG, else
  19. #endif
  20. #ifdef UNICODE
  21. #define FIsSpace            FIsSpaceW
  22. #else
  23. #define FIsSpace            FIsSpaceA
  24. #endif
  25. // Context-sensitive Help utility.
  26. typedef struct _tagHELPMAP
  27.     {
  28.     DWORD   id; 
  29.     DWORD   hid;
  30.     } HELPMAP, *LPHELPMAP;
  31. BOOL OnContextHelp(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, HELPMAP const * rgCtxMap);
  32. ULONG UlStripWhitespace(LPTSTR lpsz, BOOL fLeading, BOOL fTrailing, ULONG *pcb);
  33. void    EncodeUserPassword(TCHAR *lpszPwd, ULONG *cb);
  34. void    DecodeUserPassword(TCHAR *lpszPwd, ULONG *cb);
  35. STDAPI WriteIdentityPassword(GUID *puidIdentity, PASSWORD_STORE  *pPwdStore);
  36. STDAPI  ReadIdentityPassword(GUID *puidIdentity, PASSWORD_STORE  *pPwdStore);
  37. STDAPI  CreatePStore(IPStore **ppIPStore);
  38. STDAPI  ReleasePStore(IPStore *pIPStore);
  39. // --------------------------------------------------------------------------------
  40. // SafeRelease - Releases an object and sets the object to NULL
  41. // --------------------------------------------------------------------------------
  42. #define SafeRelease(_object) 
  43.     if (_object) { 
  44.         (_object)->Release(); 
  45.         (_object) = NULL; 
  46.     } else
  47. // --------------------------------------------------------------------------------
  48. // Memory Utility Functions
  49. // --------------------------------------------------------------------------------
  50. extern IMalloc *g_pMalloc;
  51. // --------------------------------------------------------------------------------
  52. // SafeMemFree
  53. // --------------------------------------------------------------------------------
  54. #ifndef SafeMemFree
  55. #ifdef __cplusplus
  56. #define SafeMemFree(_pv) 
  57.     if (_pv) { 
  58.         g_pMalloc->Free(_pv); 
  59.         _pv = NULL; 
  60.     } else
  61. #else
  62. #define SafeMemFree(_pv) 
  63.     if (_pv) { 
  64.         g_pMalloc->lpVtbl->Free(g_pMalloc, _pv); 
  65.         _pv = NULL; 
  66.     } else
  67. #endif // __cplusplus
  68. #endif // SafeMemFree
  69. // --------------------------------------------------------------------------------
  70. // MemFree
  71. // --------------------------------------------------------------------------------
  72. #define MemFree(_pv)        g_pMalloc->Free(_pv)
  73. #define ReleaseMem(_pv)     MemFree(_pv)
  74. // --------------------------------------------------------------------------------
  75. // Memory Allocation Functions
  76. // --------------------------------------------------------------------------------
  77. VOID       MemInit();
  78. VOID       MemUnInit();
  79. LPVOID     ZeroAllocate(DWORD cbSize);
  80. BOOL       MemAlloc(LPVOID* ppv, ULONG cb);
  81. BOOL       MemRealloc(LPVOID *ppv, ULONG cbNew);
  82. // --------------------------------------------------------------------------------
  83. // TraceCall(_pszFunc)
  84. // -------------------------------------------------------------------------------
  85. #ifdef DEBUG
  86. EXTERN_C void DebugStrf(LPTSTR lpszFormat, ...);
  87. #endif
  88. #if defined(DEBUG)
  89. #define TraceCall(_pszFunc) DebugStrf("%srn", _pszFunc)
  90. #else
  91. #define TraceCall(_pszFunc)
  92. #endif
  93. // --------------------------------------------------------------------------------
  94. // GUID <-> Ascii string functions
  95. // --------------------------------------------------------------------------------
  96. HRESULT GUIDFromAString(TCHAR *lpsz, GUID *puid);
  97. int     AStringFromGUID(GUID *rguid,  TCHAR *lpsz, int cch);
  98. // --------------------------------------------------------------------------------
  99. // Declarations for overloading global new and delete.
  100. // --------------------------------------------------------------------------------
  101. void * __cdecl operator new(size_t size);
  102. void __cdecl operator delete(void *ptr) throw();
  103. typedef enum 
  104. {
  105.     NS_NONE = 0,
  106.     NS_PRE_NOTIFY,
  107.     NS_NOTIFIED
  108. } NOTIFICATION_STATE;
  109. typedef struct tagUNKLIST_ENTRY
  110. {
  111.     HWND        hwnd;
  112.     DWORD       dwThreadId;
  113.     DWORD       dwCookie;
  114.     BYTE        bState;
  115.     IUnknown   *punk;
  116. } UNKLIST_ENTRY;
  117. class CNotifierList
  118. {
  119. public:
  120.                             CNotifierList();
  121.     virtual                 ~CNotifierList();
  122.     STDMETHODIMP_(ULONG)    AddRef(void);
  123.     STDMETHODIMP_(ULONG)    Release(void);
  124.     inline  DWORD           GetLength(void)      {return m_count;}
  125.             HRESULT         Add(IUnknown *punk, DWORD *pdwCookie);
  126.             HRESULT         RemoveCookie(DWORD dwCookie);
  127.             HRESULT         Remove(int iIndex);
  128.             HRESULT         GetAtIndex(int iIndex, IUnknown **ppunk);  
  129.             HRESULT         CreateNotifyWindow();
  130.             HRESULT         ReleaseWindow();
  131.             HRESULT         SendNotification(UINT msg, DWORD dwType);
  132.             HRESULT         PreNotify();
  133.             int             GetNextNotify();
  134. private:
  135.     ULONG               m_cRef;
  136.     int                 m_count;
  137.     int                 m_ptrCount;
  138.     DWORD               m_nextCookie;
  139.     UNKLIST_ENTRY      *m_entries;      
  140.     CRITICAL_SECTION    m_rCritSect;
  141. };
  142. #endif  //__MULTIUTL_H