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.

159 lines
2.4 KiB

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