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.

132 lines
3.0 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
  4. //
  5. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  6. // This sample shows you how to implement an SP according to the WMDM documentation.
  7. // This sample uses fixed drives on your PC to emulate portable media, and
  8. // shows the relationship between different interfaces and objects. Each hard disk
  9. // volume is enumerated as a device and directories and files are enumerated as
  10. // Storage objects under respective devices. You can copy non-SDMI compliant content
  11. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  12. // device, the device must be able to report a hardware embedded serial number.
  13. // Hard disks do not have such serial numbers.
  14. //
  15. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  16. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  17. // then build the sample application from the WMDMAPP directory to see how it gets
  18. // loaded by the application. However, you need to obtain a certificate from
  19. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  20. // under the INCLUDE directory for one level up.
  21. #include "hdspPCH.h"
  22. #include "wmdmlog_i.c"
  23. BOOL fIsLoggingEnabled( VOID )
  24. {
  25. static BOOL fEnabled = FALSE;
  26. HRESULT hr;
  27. IWMDMLogger *pLogger = NULL;
  28. static BOOL fChecked = FALSE;
  29. if( !fChecked )
  30. {
  31. fChecked = TRUE;
  32. hr = CoCreateInstance(
  33. CLSID_WMDMLogger,
  34. NULL,
  35. CLSCTX_INPROC_SERVER,
  36. IID_IWMDMLogger,
  37. (void**)&pLogger
  38. );
  39. CORg( hr );
  40. hr = pLogger->IsEnabled( &fEnabled );
  41. CORg( hr );
  42. }
  43. Error:
  44. if( NULL != pLogger )
  45. {
  46. pLogger->Release();
  47. pLogger = NULL;
  48. }
  49. return fEnabled;
  50. }
  51. HRESULT hrLogString(LPSTR pszMessage, HRESULT hrSev)
  52. {
  53. HRESULT hr=S_OK;
  54. IWMDMLogger *pLogger = NULL;
  55. if( !fIsLoggingEnabled() )
  56. {
  57. return S_FALSE;
  58. }
  59. hr = CoCreateInstance(
  60. CLSID_WMDMLogger,
  61. NULL,
  62. CLSCTX_INPROC_SERVER,
  63. IID_IWMDMLogger,
  64. (void**)&pLogger
  65. );
  66. CORg( hr );
  67. hr = pLogger->LogString(
  68. ( FAILED(hrSev) ? WMDM_LOG_SEV_ERROR : WMDM_LOG_SEV_INFO ),
  69. "MSHDSP",
  70. pszMessage
  71. );
  72. CORg( hr );
  73. Error:
  74. if( pLogger )
  75. {
  76. pLogger->Release();
  77. }
  78. return hr;
  79. }
  80. HRESULT hrLogDWORD(LPSTR pszFormat, DWORD dwValue, HRESULT hrSev)
  81. {
  82. HRESULT hr=S_OK;
  83. IWMDMLogger *pLogger = NULL;
  84. if( !fIsLoggingEnabled() )
  85. {
  86. return S_FALSE;
  87. }
  88. hr = CoCreateInstance(
  89. CLSID_WMDMLogger,
  90. NULL,
  91. CLSCTX_INPROC_SERVER,
  92. IID_IWMDMLogger,
  93. (void**)&pLogger
  94. );
  95. CORg( hr );
  96. hr = pLogger->LogDword(
  97. ( FAILED(hrSev) ? WMDM_LOG_SEV_ERROR : WMDM_LOG_SEV_INFO ),
  98. "MSHDSP",
  99. pszFormat,
  100. dwValue
  101. );
  102. CORg( hr );
  103. Error:
  104. if( pLogger )
  105. {
  106. pLogger->Release();
  107. }
  108. return hr;
  109. }