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.

203 lines
4.5 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. // MDSPEnumDevice.cpp : Implementation of CMDSPEnumDevice
  22. #include "hdspPCH.h"
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMDSPEnumDevice
  25. CMDSPEnumDevice::CMDSPEnumDevice()
  26. {
  27. CHAR szDrive[] = "?:";
  28. INT i;
  29. INT cnt;
  30. m_nCurOffset=0;
  31. for(i=0, cnt=0; i<MDSP_MAX_DRIVE_COUNT; i++)
  32. {
  33. szDrive[0] = 'A' + i;
  34. // Add all FIXED drives to the enumeration list.
  35. //
  36. // Note: some hard drives do not report as FIXED, so always add C drive.
  37. //
  38. if( UtilGetDriveType(szDrive) == DRIVE_FIXED || szDrive[0] == 'C' )
  39. {
  40. m_cEnumDriveLetter[cnt] = szDrive[0];
  41. cnt++;
  42. }
  43. }
  44. m_nMaxDeviceCount = cnt;
  45. }
  46. STDMETHODIMP CMDSPEnumDevice::Next(ULONG celt, IMDSPDevice * * ppDevice, ULONG * pceltFetched)
  47. {
  48. HRESULT hr = S_FALSE;
  49. ULONG i;
  50. CFRg(g_pAppSCServer);
  51. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  52. {
  53. CORg(WMDM_E_NOTCERTIFIED);
  54. }
  55. CARg(ppDevice);
  56. CARg(pceltFetched);
  57. *pceltFetched = 0;
  58. *ppDevice = NULL;
  59. for(i=0; (i<celt)&&(m_nCurOffset<m_nMaxDeviceCount); i++)
  60. {
  61. CComObject<CMDSPDevice> *pObj;
  62. CHRg(CComObject<CMDSPDevice>::CreateInstance(&pObj));
  63. hr = pObj->QueryInterface(
  64. IID_IMDSPDevice,
  65. reinterpret_cast<void**>(&(ppDevice[i]))
  66. );
  67. if( FAILED(hr) )
  68. {
  69. delete pObj;
  70. break;
  71. }
  72. else
  73. {
  74. *pceltFetched = (*pceltFetched) + 1;
  75. pObj->m_wcsName[0] = m_cEnumDriveLetter[m_nCurOffset];
  76. pObj->m_wcsName[1] = L':';
  77. pObj->m_wcsName[2] = NULL;
  78. m_nCurOffset ++;
  79. pObj->InitGlobalDeviceInfo();
  80. }
  81. }
  82. if( SUCCEEDED(hr) )
  83. {
  84. hr = ( *pceltFetched == celt ) ? S_OK : S_FALSE;
  85. }
  86. Error:
  87. hrLogDWORD("IMSDPEnumDevice::Next returned 0x%08lx", hr, hr);
  88. return hr;
  89. }
  90. STDMETHODIMP CMDSPEnumDevice::Skip(ULONG celt, ULONG *pceltFetched)
  91. {
  92. HRESULT hr;
  93. CFRg(g_pAppSCServer);
  94. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  95. {
  96. CORg(WMDM_E_NOTCERTIFIED);
  97. }
  98. CARg(pceltFetched);
  99. if( celt <= m_nMaxDeviceCount-m_nCurOffset )
  100. {
  101. *pceltFetched = celt;
  102. m_nCurOffset += celt;
  103. hr = S_OK;
  104. }
  105. else
  106. {
  107. *pceltFetched = m_nMaxDeviceCount - m_nCurOffset;
  108. m_nCurOffset = m_nMaxDeviceCount;
  109. hr = S_FALSE;
  110. }
  111. Error:
  112. hrLogDWORD("IMSDPEnumDevice::Skip returned 0x%08lx", hr, hr);
  113. return hr;
  114. }
  115. STDMETHODIMP CMDSPEnumDevice::Reset()
  116. {
  117. HRESULT hr;
  118. CFRg(g_pAppSCServer);
  119. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  120. {
  121. CORg(WMDM_E_NOTCERTIFIED);
  122. }
  123. m_nCurOffset = 0;
  124. hr = S_OK;
  125. Error:
  126. hrLogDWORD("IMSDPEnumDevice::Reset returned 0x%08lx", hr, hr);
  127. return hr;
  128. }
  129. STDMETHODIMP CMDSPEnumDevice::Clone(IMDSPEnumDevice * * ppEnumDevice)
  130. {
  131. HRESULT hr;
  132. CComObject<CMDSPEnumDevice> *pEnumObj;
  133. CFRg(g_pAppSCServer);
  134. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  135. {
  136. CORg(WMDM_E_NOTCERTIFIED);
  137. }
  138. CARg(ppEnumDevice);
  139. hr = CComObject<CMDSPEnumDevice>::CreateInstance(&pEnumObj);
  140. if( SUCCEEDED(hr) )
  141. {
  142. hr = pEnumObj->QueryInterface(
  143. IID_IMDSPEnumDevice,
  144. reinterpret_cast<void**>(ppEnumDevice)
  145. );
  146. if( FAILED(hr) )
  147. {
  148. delete pEnumObj;
  149. goto Error;
  150. }
  151. }
  152. hr = S_OK;
  153. Error:
  154. hrLogDWORD("IMSDPEnumDevice::Clone returned 0x%08lx", hr, hr);
  155. return hr;
  156. }