Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Active Directory Property Page Sample
  4. //
  5. // The code contained in this source file is for demonstration purposes only.
  6. // No warrantee is expressed or implied and Microsoft disclaims all liability
  7. // for the consequenses of the use of this source code.
  8. //
  9. // Microsoft Windows
  10. // Copyright (C) Microsoft Corporation, 1992 - 1999
  11. //
  12. // File: page.h
  13. //
  14. // Contents: Active Directory object property page sample class header
  15. //
  16. // Classes: CDsPropPageHost, CDsPropPageHostCF, CDsPropPage
  17. //
  18. // History: 8-Sep-97 Eric Brown created
  19. //
  20. // This code produces a dynlink library called proppage.dll. It adds a new
  21. // property page to an Active Directory object class for a new attribute
  22. // called Spending-Limit (LDAP display name: spendingLimit). To use this DLL,
  23. // you need to modify the Display Specifier for the class of interest by
  24. // adding the following value:
  25. // 10,{cca62184-294f-11d1-bcfe-00c04fd8d5b6}
  26. // to the adminPropertyPages attribute. Then run regsvr32 proppage.dll. You
  27. // also need to modify the schema by creating the string attribute
  28. // Spending-Limit and adding it to the May-Contain list for the class. Now
  29. // start Active Directory Manager and open properties on an object of the
  30. // applicable class and you should see the new property page.
  31. //
  32. //-----------------------------------------------------------------------------
  33. #ifndef _PAGE_H_
  34. #define _PAGE_H_
  35. #include <windows.h>
  36. #include <ole2.h>
  37. #include <activeds.h>
  38. #include <shlobj.h> // needed for dsclient.h
  39. #include <dsclient.h>
  40. #include <adsprop.h>
  41. #include "resource.h"
  42. extern HINSTANCE g_hInstance;
  43. extern CLIPFORMAT g_cfDsObjectNames;
  44. extern const CLSID CLSID_SamplePage;
  45. #define ByteOffset(base, offset) (((LPBYTE)base)+offset)
  46. //
  47. // a couple of helper classes for dll ref. counting.
  48. //
  49. class CDll
  50. {
  51. public:
  52. static ULONG AddRef() { return InterlockedIncrement((LONG*)&s_cObjs); }
  53. static ULONG Release() { return InterlockedDecrement((LONG*)&s_cObjs); }
  54. static void LockServer(BOOL fLock) {
  55. (fLock == TRUE) ? InterlockedIncrement((LONG*)&s_cLocks)
  56. : InterlockedDecrement((LONG*)&s_cLocks);
  57. }
  58. static HRESULT CanUnloadNow(void) {
  59. return (0L == s_cObjs && 0L == s_cLocks) ? S_OK : S_FALSE;
  60. }
  61. static ULONG s_cObjs;
  62. static ULONG s_cLocks;
  63. }; // class CDll
  64. class CDllRef
  65. {
  66. public:
  67. CDllRef(void) { CDll::AddRef(); }
  68. ~CDllRef(void) { CDll::Release(); }
  69. }; // class CDllRef
  70. //+----------------------------------------------------------------------------
  71. //
  72. // Class: CDsPropPageHost
  73. //
  74. // Purpose: Property pages host object class. This is the COM object that
  75. // creates the property page(s).
  76. //
  77. //-----------------------------------------------------------------------------
  78. class CDsPropPageHost : public IShellExtInit, IShellPropSheetExt
  79. {
  80. public:
  81. CDsPropPageHost();
  82. ~CDsPropPageHost();
  83. //
  84. // IUnknown methods
  85. //
  86. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  87. STDMETHOD_(ULONG, AddRef)(void);
  88. STDMETHOD_(ULONG, Release)(void);
  89. //
  90. // IShellExtInit methods
  91. //
  92. STDMETHOD(Initialize)(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj,
  93. HKEY hKeyID );
  94. //
  95. // IShellPropSheetExt methods
  96. //
  97. STDMETHOD(AddPages)(LPFNADDPROPSHEETPAGE pAddPageProc, LPARAM lParam);
  98. STDMETHOD(ReplacePage)(UINT uPageID, LPFNADDPROPSHEETPAGE pReplacePageFunc,
  99. LPARAM lParam);
  100. private:
  101. LPDATAOBJECT m_pDataObj;
  102. unsigned long m_uRefs;
  103. CDllRef m_DllRef;
  104. };
  105. //+----------------------------------------------------------------------------
  106. //
  107. // Class: CDsPropPageHostCF
  108. //
  109. // Purpose: object class factory
  110. //
  111. //-----------------------------------------------------------------------------
  112. class CDsPropPageHostCF : public IClassFactory
  113. {
  114. public:
  115. CDsPropPageHostCF();
  116. ~CDsPropPageHostCF();
  117. // IUnknown methods
  118. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  119. STDMETHOD_(ULONG, AddRef)();
  120. STDMETHOD_(ULONG, Release)();
  121. // IClassFactory methods
  122. STDMETHOD(CreateInstance)(IUnknown * pUnkOuter, REFIID riid,
  123. void ** ppvObject);
  124. STDMETHOD(LockServer)(BOOL fLock);
  125. static IClassFactory * Create(void);
  126. private:
  127. unsigned long m_uRefs;
  128. CDllRef m_DllRef;
  129. };
  130. //
  131. // static wind proc
  132. //
  133. static LRESULT CALLBACK StaticDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam,
  134. LPARAM lParam);
  135. //+----------------------------------------------------------------------------
  136. //
  137. // Class: CDsPropPage
  138. //
  139. // Purpose: property page object class
  140. //
  141. //-----------------------------------------------------------------------------
  142. class CDsPropPage
  143. {
  144. public:
  145. CDsPropPage(HWND hNotifyObj);
  146. ~CDsPropPage(void);
  147. HRESULT Init(PWSTR pwzObjName, PWSTR pwzClass);
  148. HRESULT CreatePage(HPROPSHEETPAGE * phPage);
  149. void SetDirty(void) {
  150. PropSheet_Changed(GetParent(m_hPage), m_hPage);
  151. m_fPageDirty = TRUE;
  152. };
  153. static UINT CALLBACK PageCallback(HWND hwnd, UINT uMsg,
  154. LPPROPSHEETPAGE ppsp);
  155. //
  156. // Member functions, called by WndProc
  157. //
  158. LRESULT OnInitDialog(LPARAM lParam);
  159. LRESULT OnCommand(int id, HWND hwndCtl, UINT codeNotify);
  160. LRESULT OnNotify(UINT uMessage, WPARAM wParam, LPARAM lParam);
  161. LRESULT OnApply(void);
  162. LRESULT OnPSMQuerySibling(WPARAM wParam, LPARAM lParam);
  163. LRESULT OnPSNSetActive(LPARAM lParam);
  164. LRESULT OnPSNKillActive(LPARAM lParam);
  165. //
  166. // Data members
  167. //
  168. HWND m_hPage;
  169. IDirectoryObject * m_pDsObj;
  170. BOOL m_fInInit;
  171. BOOL m_fPageDirty;
  172. PWSTR m_pwzObjPathName;
  173. PWSTR m_pwzObjClass;
  174. PWSTR m_pwzRDName;
  175. HWND m_hNotifyObj;
  176. PADS_ATTR_INFO m_pWritableAttrs;
  177. CDllRef m_DllRef;
  178. HRESULT m_hrInit;
  179. };
  180. #endif // _PAGE_H_