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.

201 lines
4.6 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // � 1999 Microsoft Corporation. All rights reserved.
  4. //
  5. // Refer to your End User License Agreement for details on your rights/restrictions to use these sample files.
  6. //
  7. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  8. // This sample shows you how to implement an SP according to the WMDM documentation.
  9. // This sample uses fixed drives on your PC to emulate portable media, and
  10. // shows the relationship between different interfaces and objects. Each hard disk
  11. // volume is enumerated as a device and directories and files are enumerated as
  12. // Storage objects under respective devices. You can copy non-SDMI compliant content
  13. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  14. // device, the device must be able to report a hardware embedded serial number.
  15. // Hard disks do not have such serial numbers.
  16. //
  17. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  18. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  19. // then build the sample application from the WMDMAPP directory to see how it gets
  20. // loaded by the application. However, you need to obtain a certificate from
  21. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  22. // under the INCLUDE directory for one level up.
  23. // MDSPEnumDevice.cpp : Implementation of CMDSPEnumDevice
  24. #include "hdspPCH.h"
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMDSPEnumDevice
  27. CMDSPEnumDevice::CMDSPEnumDevice()
  28. {
  29. CHAR szDrive[] = "?:";
  30. INT i;
  31. INT cnt;
  32. m_nCurOffset=0;
  33. for(i=LYRA_START_DRIVE_NUM, cnt=0; i<MDSP_MAX_DRIVE_COUNT; i++)
  34. {
  35. szDrive[0] = 'A' + i;
  36. if( UtilGetLyraDriveType(szDrive) == DRIVE_LYRA_TYPE )
  37. {
  38. m_cEnumDriveLetter[cnt] = szDrive[0];
  39. cnt++;
  40. }
  41. }
  42. m_nMaxDeviceCount = cnt;
  43. }
  44. STDMETHODIMP CMDSPEnumDevice::Next(ULONG celt, IMDSPDevice * * ppDevice, ULONG * pceltFetched)
  45. {
  46. HRESULT hr = S_FALSE;
  47. ULONG i;
  48. CFRg(g_pAppSCServer);
  49. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  50. {
  51. CORg(WMDM_E_NOTCERTIFIED);
  52. }
  53. CARg(ppDevice);
  54. CARg(pceltFetched);
  55. *pceltFetched = 0;
  56. *ppDevice = NULL;
  57. for(i=0; (i<celt)&&(m_nCurOffset<m_nMaxDeviceCount); i++)
  58. {
  59. CComObject<CMDSPDevice> *pObj;
  60. CHRg(CComObject<CMDSPDevice>::CreateInstance(&pObj));
  61. hr = pObj->QueryInterface(
  62. IID_IMDSPDevice,
  63. reinterpret_cast<void**>(&(ppDevice[i]))
  64. );
  65. if( FAILED(hr) )
  66. {
  67. delete pObj;
  68. break;
  69. }
  70. else
  71. {
  72. *pceltFetched = (*pceltFetched) + 1;
  73. pObj->m_wcsName[0] = m_cEnumDriveLetter[m_nCurOffset];
  74. pObj->m_wcsName[1] = L':';
  75. pObj->m_wcsName[2] = NULL;
  76. m_nCurOffset ++;
  77. pObj->InitGlobalDeviceInfo();
  78. }
  79. }
  80. if( SUCCEEDED(hr) )
  81. {
  82. hr = ( *pceltFetched == celt ) ? S_OK : S_FALSE;
  83. }
  84. Error:
  85. hrLogDWORD("IMSDPEnumDevice::Next returned 0x%08lx", hr, hr);
  86. return hr;
  87. }
  88. STDMETHODIMP CMDSPEnumDevice::Skip(ULONG celt, ULONG *pceltFetched)
  89. {
  90. HRESULT hr;
  91. CFRg(g_pAppSCServer);
  92. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  93. {
  94. CORg(WMDM_E_NOTCERTIFIED);
  95. }
  96. CARg(pceltFetched);
  97. if( celt <= m_nMaxDeviceCount-m_nCurOffset )
  98. {
  99. *pceltFetched = celt;
  100. m_nCurOffset += celt;
  101. hr = S_OK;
  102. }
  103. else
  104. {
  105. *pceltFetched = m_nMaxDeviceCount - m_nCurOffset;
  106. m_nCurOffset = m_nMaxDeviceCount;
  107. hr = S_FALSE;
  108. }
  109. Error:
  110. hrLogDWORD("IMSDPEnumDevice::Skip returned 0x%08lx", hr, hr);
  111. return hr;
  112. }
  113. STDMETHODIMP CMDSPEnumDevice::Reset()
  114. {
  115. HRESULT hr;
  116. CFRg(g_pAppSCServer);
  117. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  118. {
  119. CORg(WMDM_E_NOTCERTIFIED);
  120. }
  121. m_nCurOffset = 0;
  122. hr = S_OK;
  123. Error:
  124. hrLogDWORD("IMSDPEnumDevice::Reset returned 0x%08lx", hr, hr);
  125. return hr;
  126. }
  127. STDMETHODIMP CMDSPEnumDevice::Clone(IMDSPEnumDevice * * ppEnumDevice)
  128. {
  129. HRESULT hr;
  130. CComObject<CMDSPEnumDevice> *pEnumObj;
  131. CFRg(g_pAppSCServer);
  132. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  133. {
  134. CORg(WMDM_E_NOTCERTIFIED);
  135. }
  136. CARg(ppEnumDevice);
  137. hr = CComObject<CMDSPEnumDevice>::CreateInstance(&pEnumObj);
  138. if( SUCCEEDED(hr) )
  139. {
  140. hr = pEnumObj->QueryInterface(
  141. IID_IMDSPEnumDevice,
  142. reinterpret_cast<void**>(ppEnumDevice)
  143. );
  144. if( FAILED(hr) )
  145. {
  146. delete pEnumObj;
  147. }
  148. else
  149. { // set the new enumerator state to be same as current
  150. pEnumObj->m_nCurOffset = m_nCurOffset;
  151. }
  152. }
  153. Error:
  154. hrLogDWORD("IMSDPEnumDevice::Clone returned 0x%08lx", hr, hr);
  155. return hr;
  156. }