Source code of Windows XP (NT5)
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.

232 lines
6.4 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: dllmisc.cxx
  13. //
  14. // Contents: AD property page sample class object handler DLL fcns.
  15. //
  16. // History: 21-Mar-97 Eric Brown created
  17. //
  18. //-----------------------------------------------------------------------------
  19. #include "page.h"
  20. HINSTANCE g_hInstance = NULL;
  21. ULONG CDll::s_cObjs = 0;
  22. ULONG CDll::s_cLocks = 0;
  23. //+----------------------------------------------------------------------------
  24. //
  25. // Function: DllMain
  26. //
  27. // Synopsis: Provide a DllMain for Win32
  28. //
  29. // Arguments: hInstance - HANDLE to this dll
  30. // dwReason - Reason this function was called. Can be
  31. // Process/Thread Attach/Detach.
  32. //
  33. // Returns: BOOL - TRUE if no error, FALSE otherwise
  34. //
  35. // History: 24-May-95 EricB created.
  36. //
  37. //-----------------------------------------------------------------------------
  38. extern "C" INT APIENTRY
  39. DllMain(HINSTANCE hInstance, DWORD dwReason, PVOID lpReserved)
  40. {
  41. switch (dwReason)
  42. {
  43. case DLL_PROCESS_ATTACH:
  44. //
  45. // Get instance handle
  46. //
  47. g_hInstance = hInstance;
  48. break;
  49. case DLL_PROCESS_DETACH:
  50. break;
  51. }
  52. return(TRUE);
  53. }
  54. //+----------------------------------------------------------------------------
  55. //
  56. // Function: DllGetClassObject
  57. //
  58. // Synopsis: Creates a class factory for the requested object.
  59. //
  60. // Arguments: [cid] - the requested class object
  61. // [iid] - the requested interface
  62. // [ppvObj] - returned pointer to class object
  63. //
  64. // Returns: HRESULTS
  65. //
  66. //-----------------------------------------------------------------------------
  67. STDAPI
  68. DllGetClassObject(REFCLSID cid, REFIID iid, void **ppvObj)
  69. {
  70. IUnknown *pUnk = NULL;
  71. HRESULT hr = S_OK;
  72. if (cid != CLSID_SamplePage)
  73. {
  74. return E_NOINTERFACE;
  75. }
  76. pUnk = CDsPropPageHostCF::Create();
  77. if (pUnk != NULL)
  78. {
  79. hr = pUnk->QueryInterface(iid, ppvObj);
  80. pUnk->Release();
  81. }
  82. else
  83. {
  84. return E_OUTOFMEMORY;
  85. }
  86. return hr;
  87. }
  88. //+----------------------------------------------------------------------------
  89. //
  90. // Function: DllCanUnloadNow
  91. //
  92. // Synopsis: Indicates whether the DLL can be removed if there are no
  93. // objects in existence.
  94. //
  95. // Returns: S_OK or S_FALSE
  96. //
  97. //-----------------------------------------------------------------------------
  98. STDAPI
  99. DllCanUnloadNow(void)
  100. {
  101. return CDll::CanUnloadNow();
  102. }
  103. TCHAR const c_szDsProppagesProgID[] = TEXT("ADsSamplePropertyPage");
  104. TCHAR const c_szServerType[] = TEXT("InProcServer32");
  105. TCHAR const c_szDsProppagesDllName[] = TEXT("proppage.dll");
  106. TCHAR const c_szThreadModel[] = TEXT("ThreadingModel");
  107. TCHAR const c_szThreadModelValue[] = TEXT("Apartment");
  108. //+----------------------------------------------------------------------------
  109. //
  110. // Function: DllRegisterServer
  111. //
  112. // Synopsis: Adds entries to the system registry.
  113. //
  114. // Returns: S_OK or S_FALSE
  115. //
  116. // Notes: The keys look like this:
  117. //
  118. // HKC\CLSID\clsid <No Name> REG_SZ name.progid
  119. // \InPropServer32 <No Name> : REG_SZ : proppage.dll
  120. // ThreadingModel : REG_SZ : Apartment
  121. //-----------------------------------------------------------------------------
  122. STDAPI
  123. DllRegisterServer(void)
  124. {
  125. HRESULT hr = S_OK;
  126. HKEY hKeyCLSID, hKeyDsPPClass, hKeySvr;
  127. long lRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("CLSID"), 0,
  128. KEY_WRITE, &hKeyCLSID);
  129. if (lRet != ERROR_SUCCESS)
  130. {
  131. return (HRESULT_FROM_WIN32(lRet));
  132. }
  133. LPOLESTR pszCLSID;
  134. DWORD dwDisposition;
  135. hr = StringFromCLSID(CLSID_SamplePage, &pszCLSID);
  136. lRet = RegCreateKeyEx(hKeyCLSID, pszCLSID, 0, NULL,
  137. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  138. &hKeyDsPPClass, &dwDisposition);
  139. if (lRet != ERROR_SUCCESS)
  140. {
  141. hr = HRESULT_FROM_WIN32(lRet);
  142. return hr;
  143. }
  144. lRet = RegSetValueEx(hKeyDsPPClass, NULL, 0, REG_SZ,
  145. (CONST BYTE *)c_szDsProppagesProgID,
  146. sizeof(TCHAR) * (wcslen(c_szDsProppagesProgID) + 1));
  147. if (lRet != ERROR_SUCCESS)
  148. {
  149. RegCloseKey(hKeyDsPPClass);
  150. hr = HRESULT_FROM_WIN32(lRet);
  151. return hr;
  152. }
  153. lRet = RegCreateKeyEx(hKeyDsPPClass, c_szServerType, 0, NULL,
  154. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  155. &hKeySvr, &dwDisposition);
  156. RegCloseKey(hKeyDsPPClass);
  157. if (lRet != ERROR_SUCCESS)
  158. {
  159. hr = HRESULT_FROM_WIN32(lRet);
  160. return hr;
  161. }
  162. lRet = RegSetValueEx(hKeySvr, NULL, 0, REG_SZ,
  163. (CONST BYTE *)c_szDsProppagesDllName,
  164. sizeof(TCHAR) * (wcslen(c_szDsProppagesDllName) + 1));
  165. if (lRet != ERROR_SUCCESS)
  166. {
  167. hr = HRESULT_FROM_WIN32(lRet);
  168. }
  169. lRet = RegSetValueEx(hKeySvr, c_szThreadModel, 0, REG_SZ,
  170. (CONST BYTE *)c_szThreadModelValue,
  171. sizeof(TCHAR) * (wcslen(c_szThreadModelValue) + 1));
  172. if (lRet != ERROR_SUCCESS)
  173. {
  174. hr = HRESULT_FROM_WIN32(lRet);
  175. }
  176. RegCloseKey(hKeySvr);
  177. RegCloseKey(hKeyCLSID);
  178. lRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, c_szDsProppagesProgID, 0, NULL,
  179. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  180. &hKeyDsPPClass, &dwDisposition);
  181. if (lRet != ERROR_SUCCESS)
  182. {
  183. hr = HRESULT_FROM_WIN32(lRet);
  184. return hr;
  185. }
  186. lRet = RegCreateKeyEx(hKeyDsPPClass, L"CLSID", 0, NULL,
  187. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  188. &hKeyCLSID, &dwDisposition);
  189. if (lRet != ERROR_SUCCESS)
  190. {
  191. hr = HRESULT_FROM_WIN32(lRet);
  192. return hr;
  193. }
  194. lRet = RegSetValueEx(hKeyCLSID, NULL, 0, REG_SZ,
  195. (CONST BYTE *)pszCLSID,
  196. sizeof(TCHAR) * (wcslen(pszCLSID) + 1));
  197. if (lRet != ERROR_SUCCESS)
  198. {
  199. hr = HRESULT_FROM_WIN32(lRet);
  200. return hr;
  201. }
  202. CoTaskMemFree(pszCLSID);
  203. return hr;
  204. }