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.

139 lines
3.3 KiB

  1. //=================================================================
  2. //
  3. // DllCommon.cpp
  4. //
  5. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include "DllCommon.h"
  10. extern HMODULE ghModule ;
  11. //***************************************************************************
  12. //
  13. // CommonGetClassObject
  14. //
  15. // Given an IID, PPVOID, Provider name, and a long ref, perform
  16. // the common tasks for a framework prover to get a class object
  17. //
  18. //***************************************************************************
  19. STDAPI CommonGetClassObject (
  20. REFIID riid,
  21. PPVOID ppv,
  22. LPCWSTR wszProviderName,
  23. LONG &lCount
  24. )
  25. {
  26. HRESULT hr = S_OK;
  27. CWbemGlueFactory *pObj = NULL;
  28. try
  29. {
  30. LogMessage2( L"%s -> DllGetClassObject", wszProviderName );
  31. pObj = new CWbemGlueFactory (&lCount) ;
  32. if (NULL != pObj)
  33. {
  34. hr = pObj->QueryInterface(riid, ppv);
  35. if (FAILED(hr))
  36. {
  37. delete pObj;
  38. pObj = NULL;
  39. }
  40. }
  41. else
  42. {
  43. hr = E_OUTOFMEMORY;
  44. }
  45. }
  46. catch ( ... )
  47. {
  48. hr = E_OUTOFMEMORY;
  49. if ( pObj != NULL )
  50. {
  51. delete pObj;
  52. }
  53. }
  54. return hr;
  55. }
  56. //***************************************************************************
  57. //
  58. // CommonGetClassObject
  59. //
  60. // Given a Provider name, and a long ref, perform
  61. // the common tasks for a framework prover to determine whether it is ready
  62. // to unload
  63. //
  64. //***************************************************************************
  65. STDAPI CommonCanUnloadNow (LPCWSTR wszProviderName, LONG &lCount)
  66. {
  67. SCODE sc = S_FALSE;
  68. try
  69. {
  70. if (CWbemProviderGlue :: FrameworkLogoffDLL ( wszProviderName, &lCount ))
  71. {
  72. sc = S_OK;
  73. LogMessage2( L"%s -> Dll CAN Unload", wszProviderName);
  74. }
  75. else
  76. {
  77. LogMessage2( L"%s -> Dll can NOT Unload", wszProviderName );
  78. }
  79. }
  80. catch ( ... )
  81. {
  82. // sc should already be set correctly
  83. }
  84. return sc;
  85. }
  86. //***************************************************************************
  87. //
  88. // CommonCommonProcessAttach
  89. //
  90. // Given a Provider name, a long ref, and the HINSTANCE passed to DLLMAIN,
  91. // perform the common tasks loading a provider.
  92. //
  93. // Note that this routine uses the extern ghModule assumed to be defined
  94. // by the caller.
  95. //
  96. //***************************************************************************
  97. BOOL STDAPICALLTYPE CommonProcessAttach(LPCWSTR wszProviderName, LONG &lCount, HINSTANCE hInstDLL)
  98. {
  99. BOOL bRet = TRUE;
  100. try
  101. {
  102. LogMessage( L"DLL_PROCESS_ATTACH" );
  103. ghModule = hInstDLL ;
  104. // Initialize once for each new process.
  105. // Return FALSE to fail DLL load.
  106. bRet = CWbemProviderGlue::FrameworkLoginDLL ( wszProviderName, &lCount ) ;
  107. if (!DisableThreadLibraryCalls(hInstDLL))
  108. {
  109. LogErrorMessage( L"DisableThreadLibraryCalls failed" );
  110. }
  111. }
  112. catch ( ... )
  113. {
  114. bRet = FALSE;
  115. }
  116. return bRet;
  117. }