| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- ///////////////////////////////////////////////////////////////////////
- // DiscRecorder.cpp
- //
- // Wrapper for IDiscRecorder2 Interface
- //
- // Written by Eric Haddan
- //
- #include "StdAfx.h"
- #include "DiscRecorder.h"
- #ifndef CDROM_EXCLUSIVE_CALLER_LENGTH
- #define CDROM_EXCLUSIVE_CALLER_LENGTH 64
- #endif
- CDiscRecorder::CDiscRecorder(void)
- : m_discRecorder(NULL)
- , m_volumePathNames(NULL)
- {
- }
- CDiscRecorder::~CDiscRecorder(void)
- {
- if (m_discRecorder != NULL)
- {
- m_discRecorder->Release();
- }
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::Initialize()
- //
- // Description:
- // Creates and initializes the IDiscRecorder2 interface
- //
- // Parameters:
- // recorderUniqueId The recorder's unique id retrieved from
- // the IDiscMaster2 interface.
- //
- bool CDiscRecorder::Initialize(const CString& recorderUniqueId)
- {
- m_recorderUniqueId = recorderUniqueId;
- //
- // Create an IDiscRecorder2
- //
- m_hResult = CoCreateInstance(__uuidof(MsftDiscRecorder2), NULL, CLSCTX_INPROC_SERVER,
- __uuidof(IDiscRecorder2), (void**)&m_discRecorder);
- ASSERT(SUCCEEDED(m_hResult));
- if (FAILED(m_hResult))
- {
- return false;
- }
- m_hResult = m_discRecorder->InitializeDiscRecorder(recorderUniqueId.AllocSysString());
- if (FAILED(m_hResult))
- {
- return false;
- }
- //
- // Get the volume name paths
- //
- m_hResult = m_discRecorder->get_VolumePathNames(&m_volumePathNames);
- ASSERT(SUCCEEDED(m_hResult));
- return true;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::AcquireExclusiveAccess()
- //
- // Description:
- // Acquires exclusive access to this device
- //
- // Parameters:
- // force forces exclusive access whether or not the device
- // can be dismounted
- // clientName The name of the client application
- //
- bool CDiscRecorder::AcquireExclusiveAccess(bool force, const CString& clientName)
- {
- int length = clientName.GetLength();
- ASSERT(!clientName.IsEmpty());
- ASSERT(length < CDROM_EXCLUSIVE_CALLER_LENGTH);
- if (length == 0 || length >= CDROM_EXCLUSIVE_CALLER_LENGTH)
- {
- return false;
- }
- for (int index = 0; index < length; index++)
- {
- TCHAR ch = clientName[index];
- if (_istalnum(ch) || ch == _T(' ') || ch == _T('.') || ch == _T(',') ||
- ch == _T(':') || ch == _T(';') || ch == _T('-') || ch == _T('_'))
- {
- continue;
- }
- //
- // Client name does not meet specification
- //
- ASSERT(FALSE);
- return false;
- }
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->AcquireExclusiveAccess(
- force ? VARIANT_TRUE : VARIANT_FALSE,
- clientName.AllocSysString());
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::ReleaseExclusiveAccess()
- //
- // Description:
- // Releases exclusive access to this device
- //
- bool CDiscRecorder::ReleaseExclusiveAccess()
- {
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->ReleaseExclusiveAccess();
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::ExclusiveAccessOwner()
- //
- // Description:
- // Returns the name of the client who has exclusive access to this
- // device.
- //
- CString CDiscRecorder::ExclusiveAccessOwner()
- {
- if (m_discRecorder != NULL)
- {
- BSTR owner = NULL;
- m_hResult = m_discRecorder->get_ExclusiveAccessOwner(&owner);
- if (SUCCEEDED(m_hResult))
- {
- return owner;
- }
- }
- return _T("");
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::EjectMedia()
- //
- // Description:
- // Elects the media on this device
- //
- bool CDiscRecorder::EjectMedia()
- {
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->EjectMedia();
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::CloseTray()
- //
- // Description:
- // Closes the tray on this device
- //
- bool CDiscRecorder::CloseTray()
- {
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->CloseTray();
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::EnableMcn()
- //
- // Description:
- // Enables the Media Change Notification on this device
- //
- bool CDiscRecorder::EnableMcn()
- {
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->EnableMcn();
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::DisableMcn()
- //
- // Description:
- // Disables the Media Change Notification on this device
- //
- bool CDiscRecorder::DisableMcn()
- {
- if (m_discRecorder != NULL)
- {
- m_hResult = m_discRecorder->DisableMcn();
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- }
- return false;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::LegacyDeviceNumber()
- //
- // Description:
- // Returns the legacy device number
- //
- LONG CDiscRecorder::GetLegacyDeviceNumber()
- {
- LONG deviceNumber = 0;
- if (m_discRecorder != NULL)
- {
- m_discRecorder->get_LegacyDeviceNumber(&deviceNumber);
- }
- return deviceNumber;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::ProductRevision()
- //
- // Description:
- // Returns the product id for this device
- //
- CString CDiscRecorder::GetProductID()
- {
- BSTR productId = NULL;
- if (m_discRecorder != NULL)
- {
- m_discRecorder->get_ProductId(&productId);
- }
- return productId;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::ProductRevision()
- //
- // Description:
- // Returns the product revision for this device
- //
- CString CDiscRecorder::GetProductRevision()
- {
- BSTR productRevision = NULL;
- if (m_discRecorder != NULL)
- {
- m_discRecorder->get_ProductRevision(&productRevision);
- }
- return productRevision;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::VendorId()
- //
- // Description:
- // Returns the vendor id for this device
- //
- CString CDiscRecorder::GetVendorId()
- {
- BSTR vendorId = NULL;
- if (m_discRecorder != NULL)
- {
- m_discRecorder->get_VendorId(&vendorId);
- }
- return vendorId;
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscRecorder::VolumeName()
- //
- // Description:
- // Returns the unique volume name associated with this device
- //
- CString CDiscRecorder::GetVolumeName()
- {
- BSTR volumeName = NULL;
- if (m_discRecorder != NULL)
- {
- m_discRecorder->get_VolumeName(&volumeName);
- }
- return volumeName;
- }
- ULONG CDiscRecorder::GetTotalVolumePaths()
- {
- if (m_volumePathNames != NULL)
- {
- return m_volumePathNames->rgsabound[0].cElements;
- }
- return 0;
- }
- CString CDiscRecorder::GetVolumePath(ULONG volumePathIndex)
- {
- ASSERT(volumePathIndex < m_volumePathNames->rgsabound[0].cElements);
- if (volumePathIndex >= m_volumePathNames->rgsabound[0].cElements)
- {
- return _T("");
- }
- return ((VARIANT*)(m_volumePathNames->pvData))[volumePathIndex].bstrVal;
- }
|