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.

160 lines
2.5 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: WMIparse.cpp
  4. // Copyright (c) 1994-2001 Microsoft Corporation, All Rights Reserved
  5. // All rights reserved.
  6. //
  7. //
  8. //
  9. //-----------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "WMIclass.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16. LONG g_lActiveClasses = 0;
  17. HMODULE g_hDll;
  18. PUID g_puid(pidWMI, pidNone);
  19. static AFX_EXTENSION_MODULE WMIparseDLL = { NULL, NULL };
  20. extern "C" int APIENTRY
  21. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  22. {
  23. UNREFERENCED_PARAMETER(lpReserved);
  24. if (dwReason == DLL_PROCESS_ATTACH)
  25. {
  26. TRACE0("WMIPARSE.DLL Initializing!\n");
  27. // Extension DLL one-time initialization
  28. AfxInitExtensionModule(WMIparseDLL, hInstance);
  29. // Insert this DLL into the resource chain
  30. new CDynLinkLibrary(WMIparseDLL);
  31. g_hDll = hInstance;
  32. }
  33. else if (dwReason == DLL_PROCESS_DETACH)
  34. {
  35. TRACE0("WMIPARSE.DLL Terminating!\n");
  36. //
  37. // If there are active classes, they WILL explode badly once the
  38. // DLL is unloaded...
  39. //
  40. LTASSERT(DllCanUnloadNow() == S_OK);
  41. AfxTermExtensionModule(WMIparseDLL);
  42. }
  43. return 1; // ok
  44. }
  45. // {74FCE960-7F7F-11ce-8311-00AA00383930}
  46. static const CLSID ciWMIParserCLSID =
  47. { 0x74fce960, 0x7f7f, 0x11ce, { 0x83, 0x11, 0x0, 0xaa, 0x0, 0x38, 0x39, 0x30 } };
  48. STDAPI_(void)
  49. DllGetParserCLSID(
  50. CLSID &ciParserCLSID)
  51. {
  52. ciParserCLSID = ciWMIParserCLSID;
  53. }
  54. STDAPI
  55. DllRegisterParser(void)
  56. {
  57. return RegisterParser(g_hDll);
  58. }
  59. STDAPI
  60. DllUnregisterParser(void)
  61. {
  62. return UnregisterParser(pidWMI, pidNone);
  63. }
  64. STDAPI
  65. DllGetClassObject(
  66. REFCLSID cidRequestedClass,
  67. REFIID iid,
  68. LPVOID *ppClassFactory)
  69. {
  70. SCODE sc = E_UNEXPECTED;
  71. *ppClassFactory = NULL;
  72. if (cidRequestedClass != ciWMIParserCLSID)
  73. {
  74. sc = CLASS_E_CLASSNOTAVAILABLE;
  75. }
  76. else
  77. {
  78. try
  79. {
  80. CWMILocClassFactory *pClassFactory;
  81. pClassFactory = new CWMILocClassFactory;
  82. sc = pClassFactory->QueryInterface(iid, ppClassFactory);
  83. pClassFactory->Release();
  84. }
  85. catch (CMemoryException *pMemoryException)
  86. {
  87. sc = E_OUTOFMEMORY;
  88. pMemoryException->Delete();
  89. }
  90. }
  91. return ResultFromScode(sc);
  92. }
  93. void
  94. IncrementClassCount(void)
  95. {
  96. InterlockedIncrement(&g_lActiveClasses);
  97. }
  98. void
  99. DecrementClassCount(void)
  100. {
  101. LTASSERT(g_lActiveClasses != 0);
  102. InterlockedDecrement(&g_lActiveClasses);
  103. }
  104. STDAPI
  105. DllCanUnloadNow(void)
  106. {
  107. SCODE sc;
  108. sc = (g_lActiveClasses == 0) ? S_OK : S_FALSE;
  109. return ResultFromScode(sc);
  110. }