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.

379 lines
9.6 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 "nds.hxx"
  16. #pragma hdrstop
  17. HINSTANCE g_hInst = NULL;
  18. extern HMODULE g_hActiveDs;
  19. WCHAR * szNDSPrefix = L"@NDS!";
  20. extern CRITICAL_SECTION g_DispTypeInfoCritSect;
  21. //---------------------------------------------------------------------------
  22. // ADs debug print, mem leak and object tracking-related stuff
  23. //---------------------------------------------------------------------------
  24. DECLARE_INFOLEVEL(ADs)
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Function: ShutDown
  28. //
  29. // Synopsis: Function to handle printing out heap debugging display
  30. //
  31. //----------------------------------------------------------------------------
  32. inline VOID ShutDown()
  33. {
  34. #if DBG==1
  35. #ifndef MSVC
  36. DUMP_TRACKING_INFO_DELETE();
  37. DeleteCriticalSection(&g_csOT);
  38. #endif // ifndef MSVC
  39. DeleteCriticalSection(&g_csDP);
  40. #endif
  41. }
  42. extern "C" DWORD heapInfoLevel;
  43. extern "C" DWORD OtInfoLevel;
  44. extern "C" DWORD ADsInfoLevel;
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Function: GetINIHeapInfoLevel
  48. //
  49. // Synopsis: Gets various infolevel values from win.ini
  50. //
  51. //----------------------------------------------------------------------------
  52. inline VOID GetINIHeapInfoLevel()
  53. {
  54. #if DBG==1
  55. const INT MAXINFOLEN=11;
  56. WCHAR awcs[MAXINFOLEN];
  57. #ifndef MSVC
  58. if (GetProfileString(L"NDS",L"heapInfoLevel", L"00000003", awcs,MAXINFOLEN))
  59. heapInfoLevel = wcstoul(awcs, NULL, 16);
  60. if (GetProfileString(L"NDS",L"Ot", L"00000003", awcs, MAXINFOLEN))
  61. OtInfoLevel = wcstoul(awcs, NULL, 16);
  62. #endif // MSVC
  63. if (GetProfileString(L"NDS",L"ADsInfoLevel", L"00000003", awcs,MAXINFOLEN))
  64. ADsInfoLevel = wcstoul(awcs, NULL, 16);
  65. #endif
  66. }
  67. // Globals
  68. ULONG g_ulObjCount = 0; // Number of objects alive in oleds.dll
  69. //+------------------------------------------------------------------------
  70. //
  71. // Macro that calculates the number of elements in a statically-defined
  72. // array.
  73. //
  74. // Note - I swiped this from ADsary.cxx - A type-safe array class. Remember
  75. // to swipe the whole thing as required.
  76. //-------------------------------------------------------------------------
  77. #define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a[0]))
  78. CNDSProviderCF g_cfProvider;
  79. CNDSNamespaceCF g_cfNamespace;
  80. CCaseIgnoreListCF g_cfCaseIgnoreList;
  81. CFaxNumberCF g_cfFaxNumber;
  82. CNetAddressCF g_cfNetAddress;
  83. COctetListCF g_cfOctetList;
  84. CEmailCF g_cfEmail;
  85. CPathCF g_cfPath;
  86. CReplicaPointerCF g_cfReplicaPointer;
  87. CTimestampCF g_cfTimestamp;
  88. CPostalAddressCF g_cfPostalAddress;
  89. CBackLinkCF g_cfBackLink;
  90. CTypedNameCF g_cfTypedName;
  91. CHoldCF g_cfHold;
  92. //+------------------------------------------------------------------------
  93. //
  94. // oleds class factories
  95. //
  96. //-------------------------------------------------------------------------
  97. struct CLSCACHE
  98. {
  99. const CLSID * pclsid;
  100. IClassFactory * pCF;
  101. };
  102. CLSCACHE g_aclscache[] =
  103. {
  104. &CLSID_NDSProvider, &g_cfProvider,
  105. &CLSID_NDSNamespace, &g_cfNamespace,
  106. &CLSID_CaseIgnoreList, &g_cfCaseIgnoreList,
  107. &CLSID_FaxNumber, &g_cfFaxNumber,
  108. &CLSID_NetAddress, &g_cfNetAddress,
  109. &CLSID_OctetList, &g_cfOctetList,
  110. &CLSID_Email, &g_cfEmail,
  111. &CLSID_Path, &g_cfPath,
  112. &CLSID_ReplicaPointer, &g_cfReplicaPointer,
  113. &CLSID_Timestamp, &g_cfTimestamp,
  114. &CLSID_PostalAddress, &g_cfPostalAddress,
  115. &CLSID_BackLink, &g_cfBackLink,
  116. &CLSID_TypedName, &g_cfTypedName,
  117. &CLSID_Hold, &g_cfHold,
  118. };
  119. //+---------------------------------------------------------------
  120. //
  121. // Function: DllGetClassObject
  122. //
  123. // Synopsis: Standard DLL entrypoint for locating class factories
  124. //
  125. //----------------------------------------------------------------
  126. STDAPI
  127. DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID FAR* ppv)
  128. {
  129. HRESULT hr;
  130. size_t i;
  131. for (i = 0; i < ARRAY_SIZE(g_aclscache); i++)
  132. {
  133. if (IsEqualCLSID(clsid, *g_aclscache[i].pclsid))
  134. {
  135. hr = g_aclscache[i].pCF->QueryInterface(iid, ppv);
  136. RRETURN(hr);
  137. }
  138. }
  139. *ppv = NULL;
  140. //
  141. // Add Debugging Code to indicate that the oleds.DllGetClassObject has been called with an unknown CLSID.
  142. //
  143. return E_NOINTERFACE;
  144. }
  145. //+---------------------------------------------------------------
  146. //
  147. // Function: DllCanUnloadNow
  148. //
  149. // Synopsis: Standard DLL entrypoint to determine if DLL can be unloaded
  150. //
  151. //---------------------------------------------------------------
  152. STDAPI
  153. DllCanUnloadNow(void)
  154. {
  155. HRESULT hr;
  156. hr = S_FALSE;
  157. if (DllReadyToUnload()) {
  158. hr = S_OK;
  159. }
  160. return hr;
  161. }
  162. //+---------------------------------------------------------------
  163. //
  164. // Function: LibMain
  165. //
  166. // Synopsis: Standard DLL initialization entrypoint
  167. //
  168. //---------------------------------------------------------------
  169. EXTERN_C BOOL __cdecl
  170. LibMain(HINSTANCE hInst, ULONG ulReason, LPVOID pvReserved)
  171. {
  172. HRESULT hr;
  173. switch (ulReason)
  174. {
  175. case DLL_PROCESS_ATTACH:
  176. //
  177. // Need to trap cases of init crit sect failing.
  178. //
  179. __try {
  180. DisableThreadLibraryCalls(hInst);
  181. g_hInst = hInst;
  182. g_hActiveDs = GetModuleHandle(TEXT("activeds.dll"));
  183. #if DBG==1
  184. #ifndef MSVC
  185. InitializeCriticalSection(&g_csOT);
  186. InitializeCriticalSection(&g_csMem);
  187. #endif
  188. InitializeCriticalSection(&g_csDP);
  189. #endif
  190. InitializeCriticalSection(&g_DispTypeInfoCritSect);
  191. //
  192. // Build the global object class cache
  193. //
  194. hr = CClassCache::CreateClassCache(
  195. &pgClassCache
  196. );
  197. if (FAILED(hr)) {
  198. return(FALSE);
  199. }
  200. }
  201. __except (EXCEPTION_EXECUTE_HANDLER) {
  202. //
  203. // Critical Failure
  204. //
  205. return FALSE;
  206. }
  207. break;
  208. case DLL_PROCESS_DETACH:
  209. delete pgClassCache;
  210. // FreeTypeInfoTable();
  211. //
  212. // Delete the critsects
  213. //
  214. #if DBG==1
  215. #ifndef MSVC
  216. DeleteCriticalSection(&g_csOT);
  217. DeleteCriticalSection(&g_csMem);
  218. #endif
  219. DeleteCriticalSection(&g_csDP);
  220. #endif
  221. DeleteCriticalSection(&g_DispTypeInfoCritSect);
  222. break;
  223. default:
  224. break;
  225. }
  226. return TRUE;
  227. }
  228. //+---------------------------------------------------------------------------
  229. //
  230. // Function: DllMain
  231. //
  232. // Synopsis: entry point for NT - post .546
  233. //
  234. //----------------------------------------------------------------------------
  235. BOOL
  236. DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  237. {
  238. return LibMain((HINSTANCE)hDll, dwReason, lpReserved);
  239. }
  240. //+------------------------------------------------------------------------
  241. //
  242. // Function: GetCachedClsidIndex
  243. //
  244. // Synopsis: Returns the index of the given CLSID in the cache, or
  245. // -1 if the CLSID is not present in the cache
  246. //
  247. // Arguments: [clsid]
  248. //
  249. // Returns: int
  250. //
  251. //-------------------------------------------------------------------------
  252. int
  253. GetCachedClsidIndex(REFCLSID clsid)
  254. {
  255. int i;
  256. CLSCACHE * pclscache;
  257. for (i = 0, pclscache = g_aclscache;
  258. i < ARRAY_SIZE(g_aclscache);
  259. i ++, pclscache++)
  260. {
  261. if (IsEqualCLSID(*pclscache->pclsid, clsid))
  262. return i;
  263. }
  264. return -1;
  265. }
  266. //+------------------------------------------------------------------------
  267. //
  268. // Function: GetCachedClassFactory
  269. //
  270. // Synopsis: Returns the cached class factory with the given index.
  271. // The pointer returned has been AddRef'd.
  272. //
  273. // Arguments: [iclsid]
  274. //
  275. // Returns: IClassFactory *
  276. //
  277. //-------------------------------------------------------------------------
  278. IClassFactory *
  279. GetCachedClassFactory(int iclsid)
  280. {
  281. IClassFactory * pCF;
  282. // Assert(iclsid >= 0);
  283. // Assert(iclsid < ARRAY_SIZE(g_aclscache));
  284. pCF = g_aclscache[iclsid].pCF;
  285. pCF->AddRef();
  286. return pCF;
  287. }
  288. //+------------------------------------------------------------------------
  289. //
  290. // Function: GetCachedClsid
  291. //
  292. // Synopsis: Returns the CLSID corresponding to the given index.
  293. // Normally, code should call GetCachedClassFactory to get
  294. // the class factory directly.
  295. //
  296. // Arguments: [iclsid] -- Clsid index
  297. // [pclsid] -- Matching clsid returned in *pclsid
  298. //
  299. //-------------------------------------------------------------------------
  300. void
  301. GetCachedClsid(int iclsid, CLSID * pclsid)
  302. {
  303. // Assert(iclsid >= 0);
  304. // Assert(iclsid < ARRAY_SIZE(g_aclscache));
  305. *pclsid = *g_aclscache[iclsid].pclsid;
  306. }