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.

226 lines
6.2 KiB

  1. //------------------------------------------------------------------------------
  2. //
  3. // File: dllentry.cpp
  4. // Copyright (C) 1995-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Purpose:
  8. // Defines the initialization routines for the DLL.
  9. //
  10. // This file needs minor changes, as marked by TODO comments. However, the
  11. // functions herein are only called by the system, Espresso, or the framework,
  12. // and you should not need to look at them extensively.
  13. //
  14. // Owner:
  15. //
  16. //------------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "clasfact.h"
  19. #include "impparse.h"
  20. #define __DLLENTRY_CPP
  21. #include "dllvars.h"
  22. LONG g_lActiveClasses = 0;
  23. static AFX_EXTENSION_MODULE parseDLL = { NULL, NULL };
  24. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  25. //
  26. // Main entry point for Win32 DLL. Returns 1, asserts, or throws an exception.
  27. //------------------------------------------------------------------------------
  28. extern "C" int APIENTRY
  29. DllMain(
  30. HINSTANCE hInstance, // Instance handle of this DLL.
  31. DWORD dwReason, // Attaching or detaching.
  32. LPVOID lpReserved) // Unused.
  33. {
  34. UNREFERENCED_PARAMETER(lpReserved);
  35. if (DLL_PROCESS_ATTACH == dwReason)
  36. {
  37. LTTRACE("DLLNAME.DLL Initializing!\n"); // TODO: Change name.
  38. // Extension DLL one-time initialization.
  39. AfxInitExtensionModule(parseDLL, hInstance);
  40. // Insert this DLL into the resource chain.
  41. new CDynLinkLibrary(parseDLL);
  42. g_hDll = hInstance;
  43. g_puid.m_pid = CLocImpParser::m_pid;
  44. g_puid.m_pidParent = pidNone;
  45. }
  46. else if (DLL_PROCESS_DETACH == dwReason)
  47. {
  48. LTTRACE("DLLNAME.DLL Terminating!\n"); // TODO: Change name
  49. // If there are active classes, they WILL explode badly once the
  50. // DLL is unloaded...
  51. LTASSERT(DllCanUnloadNow() == S_OK);
  52. // Extension DLL shutdown.
  53. AfxTermExtensionModule(parseDLL);
  54. }
  55. // Return OK.
  56. return 1;
  57. } // end of ::DllMain()
  58. // TODO: Use GUIDGEN.EXE to replace this class ID with a unique one.
  59. // GUIDGEN is supplied with MSDEV (VC++ 4.0) as part of the OLE support stuff.
  60. // Run it and you'll get a little dialog box. Pick radio button 3, "static
  61. // const struct GUID = {...}". Click on the "New GUID" button, then the "Copy"
  62. // button, which puts the result in the clipboard. From there, you can just
  63. // paste it into here. Just remember to change the type to CLSID!
  64. static const CLSID ciImpParserCLSID =
  65. {0x033EA178L, 0xC126, 0x11CE, {0x89, 0x49, 0x00, 0xAA, 0x00, 0xA3, 0xF5, 0x51}};
  66. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67. //
  68. // Entry point to get the unique class ID of the parser interface.
  69. //------------------------------------------------------------------------------
  70. STDAPI_(void)
  71. DllGetParserCLSID(
  72. CLSID &ciParserCLSID) // Place to return parser interface class ID.
  73. {
  74. ciParserCLSID = ciImpParserCLSID;
  75. return;
  76. } // end of ::DllGetParserCLSID()
  77. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  78. //
  79. // Entry point to register this parser. Calls base implementation in ESPUTIL.
  80. //------------------------------------------------------------------------------
  81. STDAPI
  82. DllRegisterParser()
  83. {
  84. LTASSERT(g_hDll != NULL);
  85. HRESULT hr = ResultFromScode(E_UNEXPECTED);
  86. hr = RegisterParser(g_hDll);
  87. return ResultFromScode(hr);
  88. } // end of ::DllRegisterParser()
  89. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  90. //
  91. // Entry point to unregister this parser. Calls the base implementation in
  92. // ESPUTIL.
  93. //------------------------------------------------------------------------------
  94. STDAPI
  95. DllUnregisterParser()
  96. {
  97. LTASSERT(g_hDll != NULL);
  98. HRESULT hr = ResultFromScode(E_UNEXPECTED);
  99. hr = UnregisterParser(CLocImpParser::m_pid, pidNone);
  100. return ResultFromScode(hr);
  101. } // end of ::DllUnregisterParser()
  102. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  103. //
  104. // Entry point to return the class factory interface.
  105. //
  106. // Return values: some sort of result code
  107. // ppClassFactory points to a CLocImpClassFactory object
  108. // on success
  109. //------------------------------------------------------------------------------
  110. STDAPI
  111. DllGetClassObject(
  112. REFCLSID cidRequestedClass, // Class ID for desired parser interfaces.
  113. REFIID iid, // Desired parser interface.
  114. LPVOID *ppClassFactory) // Return pointer to object with interface.
  115. // Note that it's a hidden double pointer!
  116. {
  117. LTASSERT(ppClassFactory != NULL);
  118. SCODE sc = E_UNEXPECTED;
  119. *ppClassFactory = NULL;
  120. if (cidRequestedClass != ciImpParserCLSID)
  121. {
  122. sc = CLASS_E_CLASSNOTAVAILABLE;
  123. }
  124. else
  125. {
  126. try
  127. {
  128. CLocImpClassFactory *pClassFactory;
  129. pClassFactory = new CLocImpClassFactory;
  130. sc = pClassFactory->QueryInterface(iid, ppClassFactory);
  131. pClassFactory->Release();
  132. }
  133. catch (CMemoryException *pMemExcep)
  134. {
  135. sc = E_OUTOFMEMORY;
  136. pMemExcep->Delete();
  137. }
  138. }
  139. return ResultFromScode(sc);
  140. } // end of ::DllGetClassObject()
  141. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  142. //
  143. // Entry point to query if the DLL can unload.
  144. //------------------------------------------------------------------------------
  145. STDAPI
  146. DllCanUnloadNow()
  147. {
  148. SCODE sc;
  149. sc = (0 == g_lActiveClasses) ? S_OK : S_FALSE;
  150. return ResultFromScode(sc);
  151. } // end of ::DllCanUnloadNow()
  152. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  153. //
  154. // Global function used in the parser to increment the active class count.
  155. //------------------------------------------------------------------------------
  156. void
  157. IncrementClassCount()
  158. {
  159. InterlockedIncrement(&g_lActiveClasses);
  160. return;
  161. } // end of ::IncrementClassCount()
  162. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  163. //
  164. // Global function used in the parser to decrement the active class count.
  165. //------------------------------------------------------------------------------
  166. void
  167. DecrementClassCount()
  168. {
  169. LTASSERT(g_lActiveClasses != 0);
  170. InterlockedDecrement(&g_lActiveClasses);
  171. return;
  172. } // end of ::DecrementClassCount()