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.

96 lines
1.9 KiB

  1. #include "stdafx.h"
  2. #include "loghelp.h"
  3. #include <wmdmlog_i.c>
  4. BOOL fIsLoggingEnabled( VOID )
  5. {
  6. HRESULT hr;
  7. IWMDMLogger *pLogger = NULL;
  8. static BOOL fChecked = FALSE;
  9. static BOOL fEnabled = FALSE;
  10. if( !fChecked )
  11. {
  12. fChecked = TRUE;
  13. hr = CoCreateInstance(CLSID_WMDMLogger, NULL, CLSCTX_INPROC_SERVER, IID_IWMDMLogger, (void**)&pLogger);
  14. if (FAILED(hr))
  15. {
  16. goto exit;
  17. }
  18. hr = pLogger->IsEnabled(&fEnabled);
  19. if (FAILED(hr))
  20. {
  21. goto exit;
  22. }
  23. }
  24. exit:
  25. if( NULL != pLogger )
  26. {
  27. pLogger->Release();
  28. pLogger = NULL;
  29. }
  30. return fEnabled;
  31. }
  32. HRESULT hrLogString(LPSTR pszMessage, HRESULT hrSev)
  33. {
  34. HRESULT hr;
  35. IWMDMLogger *pLogger = NULL;
  36. DWORD dwFlags = ( FAILED(hrSev) ? WMDM_LOG_SEV_ERROR : WMDM_LOG_SEV_INFO );
  37. if( !fIsLoggingEnabled() )
  38. {
  39. return S_FALSE;
  40. }
  41. hr = CoCreateInstance(CLSID_WMDMLogger, NULL, CLSCTX_INPROC_SERVER, IID_IWMDMLogger, (void**)&pLogger);
  42. if (FAILED(hr))
  43. {
  44. goto exit;
  45. }
  46. hr = pLogger->LogString(dwFlags, "WMDM", pszMessage);
  47. if (FAILED(hr))
  48. {
  49. goto exit;
  50. }
  51. exit:
  52. if (pLogger)
  53. pLogger->Release();
  54. return hr;
  55. }
  56. HRESULT hrLogDWORD(LPSTR pszFormat, DWORD dwValue, HRESULT hrSev)
  57. {
  58. HRESULT hr;
  59. IWMDMLogger *pLogger = NULL;
  60. DWORD dwFlags = ( FAILED(hrSev) ? WMDM_LOG_SEV_ERROR : WMDM_LOG_SEV_INFO );
  61. if( !fIsLoggingEnabled() )
  62. {
  63. return S_FALSE;
  64. }
  65. hr = CoCreateInstance(CLSID_WMDMLogger, NULL, CLSCTX_INPROC_SERVER, IID_IWMDMLogger, (void**)&pLogger);
  66. if (FAILED(hr))
  67. {
  68. goto exit;
  69. }
  70. hr = pLogger->LogDword(dwFlags, "WMDM", pszFormat, dwValue);
  71. if (FAILED(hr))
  72. {
  73. goto exit;
  74. }
  75. exit:
  76. if (pLogger)
  77. pLogger->Release();
  78. return hr;
  79. }