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.

262 lines
6.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: libmain.cxx
  7. //
  8. // Contents: LibMain for nds.dll
  9. //
  10. // Functions: LibMain, DllGetClassObject
  11. //
  12. // History: 25-Oct-94 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldap.hxx"
  16. #pragma hdrstop
  17. HINSTANCE g_hInst = NULL;
  18. //---------------------------------------------------------------------------
  19. // ADs debug print, mem leak and object tracking-related stuff
  20. //---------------------------------------------------------------------------
  21. DECLARE_INFOLEVEL(ADs)
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Function: ShutDown
  25. //
  26. // Synopsis: Function to handle printing out heap debugging display
  27. //
  28. //----------------------------------------------------------------------------
  29. inline VOID ShutDown()
  30. {
  31. #if DBG==1
  32. #ifndef MSVC
  33. DUMP_TRACKING_INFO_DELETE();
  34. DeleteCriticalSection(&g_csOT);
  35. #endif // ifndef MSVC
  36. DeleteCriticalSection(&g_csDP);
  37. #endif
  38. }
  39. extern "C" DWORD heapInfoLevel;
  40. extern "C" DWORD OtInfoLevel;
  41. extern "C" DWORD ADsInfoLevel;
  42. CLDAPUserCF g_cfUser;
  43. CLDAPOrganizationCF g_cfOrganization;
  44. CLDAPOrganizationUnitCF g_cfOrganizationUnit;
  45. CLDAPLocalityCF g_cfLocality;
  46. CLDAPPrintQueueCF g_cfPrintQueue;
  47. CLDAPGroupCF g_cfGroup;
  48. extern CRITICAL_SECTION g_ExtTypeInfoCritSect;
  49. extern CRITICAL_SECTION g_DispTypeInfoCritSect;
  50. extern CRITICAL_SECTION g_ServerListCritSect;
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: GetINIHeapInfoLevel
  54. //
  55. // Synopsis: Gets various infolevel values from win.ini
  56. //
  57. //----------------------------------------------------------------------------
  58. inline VOID GetINIHeapInfoLevel()
  59. {
  60. #if DBG==1
  61. const INT MAXINFOLEN=11;
  62. TCHAR awcs[MAXINFOLEN];
  63. #ifndef MSVC
  64. if (GetProfileString(TEXT("LDAP"),TEXT("heapInfoLevel"), TEXT("00000003"), awcs,MAXINFOLEN))
  65. heapInfoLevel = _tcstoul(awcs, NULL, 16);
  66. if (GetProfileString(TEXT("LDAP"),TEXT("Ot"), TEXT("00000003"), awcs, MAXINFOLEN))
  67. OtInfoLevel = _tcstoul(awcs, NULL, 16);
  68. #endif // MSVC
  69. if (GetProfileString(TEXT("LDAP"),TEXT("ADsInfoLevel"), TEXT("00000003"), awcs,MAXINFOLEN))
  70. ADsInfoLevel = _tcstoul(awcs, NULL, 16);
  71. #endif
  72. }
  73. // Globals
  74. ULONG g_ulObjCount = 0; // Number of objects alive in oleds.dll
  75. //+------------------------------------------------------------------------
  76. //
  77. // oleds class factories
  78. //
  79. //-------------------------------------------------------------------------
  80. struct CLSCACHE
  81. {
  82. const CLSID * pclsid;
  83. IClassFactory * pCF;
  84. };
  85. CLSCACHE g_aclscache[] =
  86. {
  87. &CLSID_MSExtUser, &g_cfUser,
  88. &CLSID_MSExtOrganization, &g_cfOrganization,
  89. &CLSID_MSExtOrganizationUnit, &g_cfOrganizationUnit,
  90. &CLSID_MSExtLocality, &g_cfLocality,
  91. &CLSID_MSExtPrintQueue, &g_cfPrintQueue,
  92. &CLSID_MSExtGroup, &g_cfGroup
  93. };
  94. //+---------------------------------------------------------------
  95. //
  96. // Function: DllGetClassObject
  97. //
  98. // Synopsis: Standard DLL entrypoint for locating class factories
  99. //
  100. //----------------------------------------------------------------
  101. STDAPI
  102. DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID FAR* ppv)
  103. {
  104. HRESULT hr;
  105. size_t i;
  106. for (i = 0; i < ARRAY_SIZE(g_aclscache); i++)
  107. {
  108. if (IsEqualCLSID(clsid, *g_aclscache[i].pclsid))
  109. {
  110. hr = g_aclscache[i].pCF->QueryInterface(iid, ppv);
  111. RRETURN(hr);
  112. }
  113. }
  114. *ppv = NULL;
  115. //
  116. // Add Debugging Code to indicate that the oleds.DllGetClassObject has been called with an unknown CLSID.
  117. //
  118. return E_NOINTERFACE;
  119. }
  120. //+---------------------------------------------------------------
  121. //
  122. // Function: DllCanUnloadNow
  123. //
  124. // Synopsis: Standard DLL entrypoint to determine if DLL can be unloaded
  125. //
  126. //---------------------------------------------------------------
  127. STDAPI
  128. DllCanUnloadNow(void)
  129. {
  130. HRESULT hr;
  131. hr = S_FALSE;
  132. if (AggregateeDllCanUnload() && DllReadyToUnload()) {
  133. hr = S_OK;
  134. }
  135. return hr;
  136. }
  137. //+---------------------------------------------------------------
  138. //
  139. // Function: LibMain
  140. //
  141. // Synopsis: Standard DLL initialization entrypoint
  142. //
  143. //---------------------------------------------------------------
  144. EXTERN_C BOOL __cdecl
  145. LibMain(HINSTANCE hInst, ULONG ulReason, LPVOID pvReserved)
  146. {
  147. HRESULT hr;
  148. switch (ulReason)
  149. {
  150. case DLL_PROCESS_ATTACH:
  151. //
  152. // Catch init crit sect failing.
  153. //
  154. __try {
  155. DisableThreadLibraryCalls(hInst);
  156. g_hInst = hInst;
  157. #if DBG==1
  158. #ifndef MSVC
  159. InitializeCriticalSection(&g_csOT);
  160. InitializeCriticalSection(&g_csMem);
  161. #endif
  162. InitializeCriticalSection(&g_csDP);
  163. #endif
  164. InitializeCriticalSection(&g_ExtTypeInfoCritSect);
  165. InitializeCriticalSection(&g_DispTypeInfoCritSect);
  166. InitializeCriticalSection(&g_ServerListCritSect);
  167. }
  168. __except (EXCEPTION_EXECUTE_HANDLER) {
  169. //
  170. // Critical Failure
  171. //
  172. return FALSE;
  173. }
  174. break;
  175. case DLL_PROCESS_DETACH:
  176. AggregateeFreeTypeInfoTable();
  177. FreeServerSSLSupportList();
  178. //
  179. // Delete the critsects.
  180. #if DBG==1
  181. #ifndef MSVC
  182. DeleteCriticalSection(&g_csOT);
  183. DeleteCriticalSection(&g_csMem);
  184. #endif
  185. DeleteCriticalSection(&g_csDP);
  186. #endif
  187. DeleteCriticalSection(&g_ExtTypeInfoCritSect);
  188. DeleteCriticalSection(&g_DispTypeInfoCritSect);
  189. DeleteCriticalSection(&g_ServerListCritSect);
  190. if (g_hDllSecur32) {
  191. FreeLibrary((HMODULE)g_hDllSecur32);
  192. g_hDllSecur32 = NULL;
  193. }
  194. break;
  195. default:
  196. break;
  197. }
  198. return TRUE;
  199. }
  200. //+---------------------------------------------------------------------------
  201. //
  202. // Function: DllMain
  203. //
  204. // Synopsis: entry point for NT - post .546
  205. //
  206. //----------------------------------------------------------------------------
  207. BOOL
  208. DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  209. {
  210. return LibMain((HINSTANCE)hDll, dwReason, lpReserved);
  211. }