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.

858 lines
18 KiB

  1. // Device.cpp : Implementation of CDevice
  2. #include "stdafx.h"
  3. #include "mswmdm.h"
  4. #include "Device.h"
  5. #include "Storage.h"
  6. #include "WMDMStorageEnum.h"
  7. #include "loghelp.h"
  8. #include "scserver.h"
  9. #include "scclient.h"
  10. #include "spinfo.h"
  11. #define DISABLE_DRM_LOG
  12. #include <drmerr.h>
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CWMDMDevice
  15. extern CSecureChannelServer *g_pAppSCServer;
  16. extern CSPInfo **g_pSPs;
  17. CWMDMDevice::CWMDMDevice()
  18. : m_pDevice(NULL)
  19. {
  20. GlobalAddRef();
  21. }
  22. CWMDMDevice::~CWMDMDevice()
  23. {
  24. if (m_pDevice)
  25. m_pDevice->Release();
  26. GlobalRelease();
  27. }
  28. //IWMDMDevice Methods
  29. HRESULT CWMDMDevice::GetName(LPWSTR pwszName,
  30. UINT nMaxChars)
  31. {
  32. HRESULT hr;
  33. if (g_pAppSCServer)
  34. {
  35. if(!g_pAppSCServer->fIsAuthenticated())
  36. {
  37. CORg( WMDM_E_NOTCERTIFIED );
  38. }
  39. }
  40. else
  41. {
  42. CORg( E_FAIL );
  43. }
  44. CORg( m_pDevice->GetName(pwszName, nMaxChars) );
  45. Error:
  46. hrLogDWORD("IWMDMDevice::GetName returned 0x%08lx", hr, hr);
  47. return hr;
  48. }
  49. HRESULT CWMDMDevice::GetManufacturer(LPWSTR pwszName,
  50. UINT nMaxChars)
  51. {
  52. HRESULT hr;
  53. if (g_pAppSCServer)
  54. {
  55. if(!g_pAppSCServer->fIsAuthenticated())
  56. {
  57. CORg( WMDM_E_NOTCERTIFIED );
  58. }
  59. }
  60. else
  61. {
  62. CORg( E_FAIL );
  63. }
  64. CORg( m_pDevice->GetManufacturer(pwszName, nMaxChars) );
  65. Error:
  66. hrLogDWORD("IWMDMDevice::GetManufacturer returned 0x%08lx", hr, hr);
  67. return hr;
  68. }
  69. HRESULT CWMDMDevice::GetVersion(DWORD *pdwVersion)
  70. {
  71. HRESULT hr;
  72. if (g_pAppSCServer)
  73. {
  74. if(!g_pAppSCServer->fIsAuthenticated())
  75. {
  76. CORg( WMDM_E_NOTCERTIFIED );
  77. }
  78. }
  79. else
  80. {
  81. CORg( E_FAIL );
  82. }
  83. CORg( m_pDevice->GetVersion(pdwVersion) );
  84. Error:
  85. hrLogDWORD("IWMDMDevice::GetVersion returned 0x%08lx", hr, hr);
  86. return hr;
  87. }
  88. HRESULT CWMDMDevice::GetType(DWORD *pdwType)
  89. {
  90. HRESULT hr;
  91. CARg (pdwType);
  92. if (g_pAppSCServer)
  93. {
  94. if(!g_pAppSCServer->fIsAuthenticated())
  95. {
  96. CORg( WMDM_E_NOTCERTIFIED );
  97. }
  98. }
  99. else
  100. {
  101. CORg( E_FAIL );
  102. }
  103. CORg( m_pDevice->GetType(pdwType) );
  104. #if 0
  105. //////////////////////////////////////////
  106. //RC1 Hack for non-reentrant devices
  107. //////////////////////////////////////////
  108. WCHAR wszManufacturer[MAX_PATH];
  109. CORg(m_pDevice->GetManufacturer (wszManufacturer, MAX_PATH));
  110. if (wcsstr(_wcsupr(wszManufacturer), L"S3/DIAMOND MULTIMEDIA"))
  111. {
  112. *pdwType |= WMDM_DEVICE_TYPE_NONREENTRANT | WMDM_DEVICE_TYPE_FILELISTRESYNC;
  113. }
  114. #endif
  115. //////////////////////////////////////////
  116. Error:
  117. hrLogDWORD("IWMDMDevice::GetType returned 0x%08lx", hr, hr);
  118. return hr;
  119. }
  120. HRESULT CWMDMDevice::GetSerialNumber(PWMDMID pSerialNumber, BYTE abMac[WMDM_MAC_LENGTH])
  121. {
  122. HRESULT hr;
  123. HMAC hMAC;
  124. CSecureChannelClient *pSCClient;
  125. BYTE abTempMAC[WMDM_MAC_LENGTH];
  126. BYTE abMACVerify[WMDM_MAC_LENGTH];
  127. if (g_pAppSCServer)
  128. {
  129. if(!g_pAppSCServer->fIsAuthenticated())
  130. {
  131. CORg( WMDM_E_NOTCERTIFIED );
  132. }
  133. }
  134. else
  135. {
  136. CORg( E_FAIL );
  137. }
  138. g_pSPs[m_wSPIndex]->GetSCClient(&pSCClient);
  139. if (!pSCClient)
  140. {
  141. CORg( E_FAIL );
  142. }
  143. CORg( m_pDevice->GetSerialNumber(pSerialNumber, abTempMAC) );
  144. // Verify the MAC from SP
  145. CORg( pSCClient->MACInit(&hMAC) );
  146. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(pSerialNumber), sizeof(WMDMID)) );
  147. CORg( pSCClient->MACFinal(hMAC, abMACVerify) );
  148. if (memcmp(abMACVerify, abTempMAC, WMDM_MAC_LENGTH) != 0)
  149. {
  150. CORg( WMDM_E_MAC_CHECK_FAILED );
  151. }
  152. // Compute the MAC to send back to the application
  153. CORg( g_pAppSCServer->MACInit(&hMAC) );
  154. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(pSerialNumber), sizeof(WMDMID)) );
  155. CORg( g_pAppSCServer->MACFinal(hMAC, abMac) );
  156. Error:
  157. hrLogDWORD("IWMDMDevice::GetSerialNumber returned 0x%08lx", hr, hr);
  158. return hr;
  159. }
  160. HRESULT CWMDMDevice::GetPowerSource(DWORD *pdwPowerSource,
  161. DWORD *pdwPercentRemaining)
  162. {
  163. HRESULT hr;
  164. if (g_pAppSCServer)
  165. {
  166. if(!g_pAppSCServer->fIsAuthenticated())
  167. {
  168. CORg( WMDM_E_NOTCERTIFIED );
  169. }
  170. }
  171. else
  172. {
  173. CORg( E_FAIL );
  174. }
  175. CORg( m_pDevice->GetPowerSource(pdwPowerSource, pdwPercentRemaining) );
  176. Error:
  177. hrLogDWORD("IWMDMDevice::GetPowerSource returned 0x%08lx", hr, hr);
  178. return hr;
  179. }
  180. HRESULT CWMDMDevice::GetStatus(DWORD *pdwStatus)
  181. {
  182. HRESULT hr;
  183. if (g_pAppSCServer)
  184. {
  185. if(!g_pAppSCServer->fIsAuthenticated())
  186. {
  187. CORg( WMDM_E_NOTCERTIFIED );
  188. }
  189. }
  190. else
  191. {
  192. CORg( E_FAIL );
  193. }
  194. CORg( m_pDevice->GetStatus(pdwStatus) );
  195. Error:
  196. hrLogDWORD("IWMDMDevice::GetStatus returned 0x%08lx", hr, hr);
  197. return hr;
  198. }
  199. HRESULT CWMDMDevice::EnumStorage(IWMDMEnumStorage **ppEnumStorage)
  200. {
  201. HRESULT hr;
  202. CComObject<CWMDMStorageEnum> *pEnumObj = NULL;
  203. IMDSPEnumStorage *pEnumStg = NULL;
  204. if (g_pAppSCServer)
  205. {
  206. if(!g_pAppSCServer->fIsAuthenticated())
  207. {
  208. CORg( WMDM_E_NOTCERTIFIED );
  209. }
  210. }
  211. else
  212. {
  213. CORg( E_FAIL );
  214. }
  215. CARg( ppEnumStorage );
  216. CORg( m_pDevice->EnumStorage(&pEnumStg) );
  217. CORg( CComObject<CWMDMStorageEnum>::CreateInstance(&pEnumObj) );
  218. CORg( pEnumObj->QueryInterface(IID_IWMDMEnumStorage, reinterpret_cast<void**>(ppEnumStorage)) );
  219. if (FAILED(hr))
  220. {
  221. delete pEnumObj;
  222. pEnumObj = NULL;
  223. goto Error;
  224. }
  225. pEnumObj->SetContainedPointer(pEnumStg, m_wSPIndex);
  226. Error:
  227. if(pEnumStg)
  228. pEnumStg->Release();
  229. hrLogDWORD("IWMDMDevice::EnumStorage returned 0x%08lx", hr, hr);
  230. return hr;
  231. }
  232. HRESULT CWMDMDevice::GetFormatSupport(_WAVEFORMATEX **ppFormatEx,
  233. UINT *pnFormatCount,
  234. LPWSTR **pppwszMimeType,
  235. UINT *pnMimeTypeCount)
  236. {
  237. HRESULT hr;
  238. if (g_pAppSCServer)
  239. {
  240. if(!g_pAppSCServer->fIsAuthenticated())
  241. {
  242. CORg( WMDM_E_NOTCERTIFIED );
  243. }
  244. }
  245. else
  246. {
  247. CORg( E_FAIL );
  248. }
  249. CORg( m_pDevice->GetFormatSupport(ppFormatEx, pnFormatCount, pppwszMimeType, pnMimeTypeCount) );
  250. Error:
  251. hrLogDWORD("IWMDMDevice::GetFormatSupport returned 0x%08lx", hr, hr);
  252. return hr;
  253. }
  254. HRESULT CWMDMDevice::GetDeviceIcon(ULONG *hIcon)
  255. {
  256. HRESULT hr;
  257. if (g_pAppSCServer)
  258. {
  259. if(!g_pAppSCServer->fIsAuthenticated())
  260. {
  261. CORg( WMDM_E_NOTCERTIFIED );
  262. }
  263. }
  264. else
  265. {
  266. CORg( E_FAIL );
  267. }
  268. CORg( m_pDevice->GetDeviceIcon(hIcon) );
  269. Error:
  270. hrLogDWORD("IWMDMDevice::GetDeviceIcon returned 0x%08lx", hr, hr);
  271. return hr;
  272. }
  273. HRESULT CWMDMDevice::SendOpaqueCommand(OPAQUECOMMAND *pCommand)
  274. {
  275. HRESULT hr;
  276. HMAC hMAC;
  277. CSecureChannelClient *pSCClient;
  278. BYTE abMACVerify[WMDM_MAC_LENGTH];
  279. if (g_pAppSCServer)
  280. {
  281. if(!g_pAppSCServer->fIsAuthenticated())
  282. {
  283. CORg( WMDM_E_NOTCERTIFIED );
  284. }
  285. }
  286. else
  287. {
  288. CORg( E_FAIL );
  289. }
  290. if( (pCommand == NULL) ||
  291. ((pCommand->pData == NULL) && (pCommand->dwDataLen > 0)) )
  292. {
  293. CORg( E_INVALIDARG );
  294. }
  295. // Verify the MAC from APP
  296. CORg( g_pAppSCServer->MACInit(&hMAC) );
  297. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(&(pCommand->guidCommand)), sizeof(GUID)) );
  298. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(&(pCommand->dwDataLen)), sizeof(pCommand->dwDataLen)) );
  299. if (pCommand->pData)
  300. {
  301. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(pCommand->pData), pCommand->dwDataLen) );
  302. }
  303. CORg( g_pAppSCServer->MACFinal(hMAC, abMACVerify) );
  304. if (memcmp(abMACVerify, pCommand->abMAC, WMDM_MAC_LENGTH) != 0)
  305. {
  306. CORg( WMDM_E_MAC_CHECK_FAILED );
  307. }
  308. g_pSPs[m_wSPIndex]->GetSCClient(&pSCClient);
  309. if (!pSCClient)
  310. {
  311. CORg( E_FAIL );
  312. }
  313. // Compute the MAC to send back to the SP
  314. CORg( pSCClient->MACInit(&hMAC) );
  315. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(&(pCommand->guidCommand)), sizeof(GUID)) );
  316. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(&(pCommand->dwDataLen)), sizeof(pCommand->dwDataLen)) );
  317. if (pCommand->pData)
  318. {
  319. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(pCommand->pData), pCommand->dwDataLen) );
  320. }
  321. CORg( pSCClient->MACFinal(hMAC, pCommand->abMAC) );
  322. // Pass the call down to the SP
  323. CORg( m_pDevice->SendOpaqueCommand(pCommand) );
  324. // Verify the MAC from SP
  325. CORg( pSCClient->MACInit(&hMAC) );
  326. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(&(pCommand->guidCommand)), sizeof(GUID)) );
  327. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(&(pCommand->dwDataLen)), sizeof(pCommand->dwDataLen)) );
  328. if (pCommand->pData)
  329. {
  330. CORg( pSCClient->MACUpdate(hMAC, (BYTE*)(pCommand->pData), pCommand->dwDataLen) );
  331. }
  332. CORg( pSCClient->MACFinal(hMAC, abMACVerify) );
  333. if (memcmp(abMACVerify, pCommand->abMAC, WMDM_MAC_LENGTH) != 0)
  334. {
  335. CORg( WMDM_E_MAC_CHECK_FAILED );
  336. }
  337. // Compute the MAC to send back to the application
  338. CORg( g_pAppSCServer->MACInit(&hMAC) );
  339. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(&(pCommand->guidCommand)), sizeof(GUID)) );
  340. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(&(pCommand->dwDataLen)), sizeof(pCommand->dwDataLen)) );
  341. if (pCommand->pData)
  342. {
  343. CORg( g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(pCommand->pData), pCommand->dwDataLen) );
  344. }
  345. CORg( g_pAppSCServer->MACFinal(hMAC, pCommand->abMAC) );
  346. Error:
  347. hrLogDWORD("IWMDMDevice::SendOpaqueCommand returned 0x%08lx", hr, hr);
  348. return hr;
  349. }
  350. // IWMDMDevice2
  351. HRESULT CWMDMDevice::GetStorage( LPCWSTR pszStorageName, IWMDMStorage** ppStorage )
  352. {
  353. HRESULT hr;
  354. IMDSPDevice2* pDev2 = NULL;
  355. IMDSPStorage* pMDSPStorageFound = NULL;
  356. IMDSPStorage* pMDSubStorage = NULL;
  357. CComObject<CWMDMStorage>* pStgObj = NULL;
  358. CARg( ppStorage );
  359. CARg( pszStorageName );
  360. if (g_pAppSCServer)
  361. {
  362. if(!g_pAppSCServer->fIsAuthenticated())
  363. {
  364. CORg( WMDM_E_NOTCERTIFIED );
  365. }
  366. }
  367. else
  368. {
  369. CORg( E_FAIL );
  370. }
  371. // Get the Storage pointer from the SP (as a IMDSPStorage)
  372. hr = m_pDevice->QueryInterface(IID_IMDSPDevice2, reinterpret_cast<void**>(&pDev2));
  373. if( SUCCEEDED(hr) )
  374. {
  375. hr = pDev2->GetStorage( pszStorageName, &pMDSPStorageFound );
  376. }
  377. // This functionalty is not implemented by the SP. Find the storage by enumerating all storages
  378. if( hr == E_NOTIMPL || hr == E_NOINTERFACE )
  379. {
  380. IMDSPEnumStorage *pEnum = NULL;
  381. WCHAR pswzMDSubStorageName[MAX_PATH];
  382. ULONG ulFetched;
  383. CORg(m_pDevice->EnumStorage(&pEnum));
  384. while( S_OK == pEnum->Next(1, &pMDSubStorage, &ulFetched) )
  385. {
  386. hr = pMDSubStorage->GetName( pswzMDSubStorageName, MAX_PATH );
  387. if( SUCCEEDED(hr) && ( _wcsicmp( pswzMDSubStorageName, pszStorageName ) == 0 ) )
  388. {
  389. // We have found the storage we are looking for.
  390. pMDSPStorageFound = pMDSubStorage;
  391. break;
  392. }
  393. pMDSubStorage->Release();
  394. }
  395. pEnum->Release();
  396. }
  397. // Create a IWMDMStorage object and connect it to the the storage from the SP
  398. if( pMDSPStorageFound != NULL )
  399. {
  400. CORg( CComObject<CWMDMStorage>::CreateInstance(&pStgObj) );
  401. CORg( pStgObj->QueryInterface(IID_IWMDMStorage, reinterpret_cast<void**>(ppStorage)) );
  402. pStgObj->SetContainedPointer(pMDSPStorageFound, m_wSPIndex);
  403. }
  404. // Did not find a matching storage
  405. else if( SUCCEEDED(hr) )
  406. {
  407. hr = S_FALSE;
  408. }
  409. Error:
  410. if( pDev2 )
  411. pDev2->Release();
  412. if( hr != S_OK )
  413. {
  414. ppStorage = NULL;
  415. delete pStgObj;
  416. }
  417. hrLogDWORD("IWMDMDevice2::GetStorage returned 0x%08lx", hr, hr);
  418. return hr;
  419. }
  420. HRESULT CWMDMDevice::GetFormatSupport2(
  421. DWORD dwFlags,
  422. _WAVEFORMATEX **ppAudioFormatEx,
  423. UINT *pnAudioFormatCount,
  424. _VIDEOINFOHEADER **ppVideoFormatEx,
  425. UINT *pnVideoFormatCount,
  426. WMFILECAPABILITIES **ppFileType,
  427. UINT *pnFileTypeCount)
  428. {
  429. HRESULT hr = S_OK;
  430. IMDSPDevice2* pDev2 = NULL;
  431. if (g_pAppSCServer)
  432. {
  433. if(!g_pAppSCServer->fIsAuthenticated())
  434. {
  435. CORg( WMDM_E_NOTCERTIFIED );
  436. }
  437. }
  438. else
  439. {
  440. CORg( E_FAIL );
  441. }
  442. CORg( m_pDevice->QueryInterface(IID_IMDSPDevice2, reinterpret_cast<void**>(&pDev2)) );
  443. CORg( pDev2->GetFormatSupport2( dwFlags,
  444. ppAudioFormatEx,
  445. pnAudioFormatCount,
  446. ppVideoFormatEx,
  447. pnVideoFormatCount,
  448. ppFileType,
  449. pnFileTypeCount) );
  450. Error:
  451. if( pDev2 )
  452. pDev2->Release();
  453. hrLogDWORD("IWMDMDevice2::GetFormatSupport2 returned 0x%08lx", hr, hr);
  454. return hr;
  455. }
  456. HRESULT CWMDMDevice::GetSpecifyPropertyPages(
  457. ISpecifyPropertyPages** ppSpecifyPropPages,
  458. IUnknown*** pppUnknowns,
  459. ULONG* pcUnks )
  460. {
  461. HRESULT hr = S_OK;
  462. IMDSPDevice2* pDev2 = NULL;
  463. CARg( ppSpecifyPropPages );
  464. CARg( pppUnknowns );
  465. CARg( pcUnks );
  466. if (g_pAppSCServer)
  467. {
  468. if(!g_pAppSCServer->fIsAuthenticated())
  469. {
  470. CORg( WMDM_E_NOTCERTIFIED );
  471. }
  472. }
  473. else
  474. {
  475. CORg( E_FAIL );
  476. }
  477. CORg( m_pDevice->QueryInterface(IID_IMDSPDevice2, reinterpret_cast<void**>(&pDev2)) );
  478. CORg( pDev2->GetSpecifyPropertyPages( ppSpecifyPropPages, pppUnknowns, pcUnks ) );
  479. Error:
  480. if( pDev2 )
  481. pDev2->Release();
  482. hrLogDWORD("IWMDMDevice2::GetSpecifyPropertyPages returned 0x%08lx", hr, hr);
  483. return hr;
  484. }
  485. HRESULT CWMDMDevice::GetPnPName( LPWSTR pwszPnPName, UINT nMaxChars )
  486. {
  487. HRESULT hr = S_OK;
  488. IMDSPDevice2* pDev2 = NULL;
  489. if (g_pAppSCServer)
  490. {
  491. if(!g_pAppSCServer->fIsAuthenticated())
  492. {
  493. CORg( WMDM_E_NOTCERTIFIED );
  494. }
  495. }
  496. else
  497. {
  498. CORg( E_FAIL );
  499. }
  500. CORg( m_pDevice->QueryInterface(IID_IMDSPDevice2, reinterpret_cast<void**>(&pDev2)) );
  501. CORg( pDev2->GetPnPName( pwszPnPName, nMaxChars ) );
  502. Error:
  503. if( pDev2 )
  504. {
  505. pDev2->Release();
  506. }
  507. hrLogDWORD("IWMDMDevice2::GetPnPName returned 0x%08lx", hr, hr);
  508. return hr;
  509. }
  510. // IWMDMDeviceControl
  511. HRESULT CWMDMDevice::GetCapabilities(DWORD *pdwCapabilitiesMask)
  512. {
  513. HRESULT hr;
  514. IMDSPDeviceControl *pDevCtrl = NULL;
  515. if (g_pAppSCServer)
  516. {
  517. if(!g_pAppSCServer->fIsAuthenticated())
  518. {
  519. CORg( WMDM_E_NOTCERTIFIED );
  520. }
  521. }
  522. else
  523. {
  524. CORg( E_FAIL );
  525. }
  526. if (!pdwCapabilitiesMask)
  527. {
  528. CORg( E_INVALIDARG );
  529. }
  530. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  531. CORg( pDevCtrl->GetCapabilities(pdwCapabilitiesMask) );
  532. Error:
  533. if (pDevCtrl)
  534. pDevCtrl->Release();
  535. hrLogDWORD("IWMDMDeviceControl::GetCapabilities returned 0x%08lx", hr, hr);
  536. return hr;
  537. }
  538. HRESULT CWMDMDevice::Play()
  539. {
  540. HRESULT hr;
  541. IMDSPDeviceControl *pDevCtrl = NULL;
  542. if (g_pAppSCServer)
  543. {
  544. if(!g_pAppSCServer->fIsAuthenticated())
  545. {
  546. CORg( WMDM_E_NOTCERTIFIED );
  547. }
  548. }
  549. else
  550. {
  551. CORg( E_FAIL );
  552. }
  553. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  554. CORg( pDevCtrl->Play() );
  555. Error:
  556. if (pDevCtrl)
  557. pDevCtrl->Release();
  558. hrLogDWORD("IWMDMDeviceControl::Play returned 0x%08lx", hr, hr);
  559. return hr;
  560. }
  561. HRESULT CWMDMDevice::Record(_WAVEFORMATEX *pFormat)
  562. {
  563. HRESULT hr;
  564. IMDSPDeviceControl *pDevCtrl = NULL;
  565. if (g_pAppSCServer)
  566. {
  567. if(!g_pAppSCServer->fIsAuthenticated())
  568. {
  569. CORg( WMDM_E_NOTCERTIFIED );
  570. }
  571. }
  572. else
  573. {
  574. CORg( E_FAIL );
  575. }
  576. if (!pFormat)
  577. {
  578. CORg( E_INVALIDARG );
  579. }
  580. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  581. CORg( pDevCtrl->Record(pFormat) );
  582. Error:
  583. if (pDevCtrl)
  584. pDevCtrl->Release();
  585. hrLogDWORD("IWMDMDeviceControl::Record returned 0x%08lx", hr, hr);
  586. return hr;
  587. }
  588. HRESULT CWMDMDevice::Pause()
  589. {
  590. HRESULT hr;
  591. IMDSPDeviceControl *pDevCtrl = NULL;
  592. if (g_pAppSCServer)
  593. {
  594. if(!g_pAppSCServer->fIsAuthenticated())
  595. {
  596. CORg( WMDM_E_NOTCERTIFIED );
  597. }
  598. }
  599. else
  600. {
  601. CORg( E_FAIL );
  602. }
  603. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  604. CORg( pDevCtrl->Pause() );
  605. Error:
  606. if (pDevCtrl)
  607. pDevCtrl->Release();
  608. hrLogDWORD("IWMDMDeviceControl::Pause returned 0x%08lx", hr, hr);
  609. return hr;
  610. }
  611. HRESULT CWMDMDevice::Resume()
  612. {
  613. HRESULT hr;
  614. IMDSPDeviceControl *pDevCtrl = NULL;
  615. if (g_pAppSCServer)
  616. {
  617. if(!g_pAppSCServer->fIsAuthenticated())
  618. {
  619. CORg( WMDM_E_NOTCERTIFIED );
  620. }
  621. }
  622. else
  623. {
  624. CORg( E_FAIL );
  625. }
  626. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  627. CORg( pDevCtrl->Resume() );
  628. Error:
  629. if (pDevCtrl)
  630. pDevCtrl->Release();
  631. hrLogDWORD("IWMDMDeviceControl::Resume returned 0x%08lx", hr, hr);
  632. return hr;
  633. }
  634. HRESULT CWMDMDevice::Stop()
  635. {
  636. HRESULT hr;
  637. IMDSPDeviceControl *pDevCtrl = NULL;
  638. if (g_pAppSCServer)
  639. {
  640. if(!g_pAppSCServer->fIsAuthenticated())
  641. {
  642. CORg( WMDM_E_NOTCERTIFIED );
  643. }
  644. }
  645. else
  646. {
  647. CORg( E_FAIL );
  648. }
  649. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  650. CORg( pDevCtrl->Stop() );
  651. Error:
  652. if (pDevCtrl)
  653. pDevCtrl->Release();
  654. hrLogDWORD("IWMDMDeviceControl::Stop returned 0x%08lx", hr, hr);
  655. return hr;
  656. }
  657. HRESULT CWMDMDevice::Seek(UINT fuMode, int nOffset)
  658. {
  659. HRESULT hr;
  660. IMDSPDeviceControl *pDevCtrl = NULL;
  661. if (g_pAppSCServer)
  662. {
  663. if(!g_pAppSCServer->fIsAuthenticated())
  664. {
  665. CORg( WMDM_E_NOTCERTIFIED );
  666. }
  667. }
  668. else
  669. {
  670. CORg( E_FAIL );
  671. }
  672. CORg( m_pDevice->QueryInterface(IID_IMDSPDeviceControl, reinterpret_cast<void**>(&pDevCtrl)) );
  673. CORg( pDevCtrl->Seek(fuMode, nOffset) );
  674. Error:
  675. if (pDevCtrl)
  676. pDevCtrl->Release();
  677. hrLogDWORD("IWMDMDeviceControl::Seek returned 0x%08lx", hr, hr);
  678. return hr;
  679. }
  680. void CWMDMDevice::SetContainedPointer(IMDSPDevice *pDevice, WORD wSPIndex)
  681. {
  682. m_pDevice = pDevice;
  683. m_pDevice->AddRef();
  684. m_wSPIndex = wSPIndex;
  685. return;
  686. }