알림 활성화
Windows Media Device Manager는 애플리케이션이 이벤트 알림을 수신하기 위해 COM 클래스에서 구현할 수 있는 4개의 인터페이스를 선언합니다. 다음 표와 같이 이러한 인터페이스는 두 그룹으로 나 분류됩니다.
인터페이스 | 설명 |
---|---|
IWMDMNotification | 디바이스 또는 스토리지 미디어가 연결되거나 연결이 끊어지면 애플리케이션에 알합니다. |
IWMDMProgress IWMDMProgress2 IWMDMProgress3 |
모든 이벤트의 진행 상황을 애플리케이션에 경고하는 매우 간단한 알림 시스템입니다. 애플리케이션은 이러한 메시지에 대한 응답으로 어떤 작업도 수행할 필요가 없습니다. |
IWMDMNotification
IWMDMNotification 플러그 앤 플레이 디바이스가 컴퓨터에서 연결되거나 연결이 끊어진 경우와 플러그 앤 플레이 스토리지 미디어(예: 플래시 카드)가 디바이스에서 삽입되거나 제거될 때 애플리케이션에 경고합니다. 이러한 알림은 애플리케이션이 변경 내용을 반영하도록 사용자 인터페이스를 업데이트하는 데 도움이 될 수 있습니다.
이러한 알림을 받으려면 애플리케이션이 플랫폼 SDK IConnectionPointContainer 및 IConnectionPoint 인터페이스를 사용하여 수신하도록 등록해야 합니다. 애플리케이션이 시작될 때 이벤트를 수신하도록 등록하고 닫을 때 등록을 취소해야 합니다. 다음 단계에 따라 등록하여 이러한 알림을 받습니다.
- IConnectionPointContainer대해 애플리케이션을 인증할 때 받은 기본 IWMDeviceManager 인터페이스를 쿼리합니다.
- IConnectionPointContainer::FindConnectionPoint 호출하여 IWMDMNotification 인터페이스에 대한 컨테이너 연결 지점을 검색합니다.
- IConnectionPoint::Advise호출하여 이벤트를 수신하도록 등록합니다. IWMDMNotification구현하는 클래스를 전달하고 연결점을 식별하는 고유 ID인 쿠키를 검색합니다. 이 값은 저장해야 하며 나중에 이벤트 알림 등록을 취소하는 데 사용해야 합니다.
다음 C++ 코드는 IWMDMNotification알림을 수신하도록 등록하는 방법을 보여 줍니다.
HRESULT CWMDMController::RegisterForNotifications()
{
HRESULT hr = S_OK;
CComPtr<IConnectionPointContainer> pConxnPointCont;
CComPtr<IConnectionPoint> pIConnPoint;
// Get the IConnectionPointContainer interface from IWMDeviceManager.
if (SUCCEEDED (hr = m_IWMDMDeviceMgr->QueryInterface(IID_IConnectionPointContainer, (void**) & pConxnPointCont)))
{
// Get a connection point from the container.
if (SUCCEEDED (hr = pConxnPointCont->FindConnectionPoint(IID_IWMDMNotification, &pIConnPoint)))
{
// Add ourselves as a callback handler for the connection point.
// If we succeeded, indicate that by storing the connection point ID.
DWORD dwCookie;
if (SUCCEEDED (hr = pIConnPoint->Advise((IUnknown*)((IWMDMNotification*)this), &dwCookie)))
{
m_dwNotificationCookie = dwCookie;
}
}
}
return hr;
}
애플리케이션이 닫히면 더 이상 알림을 보내지 않음을 나타내려면 IConnectionPoint 등록을 취소해야 합니다. 다음 단계에 따라 알림 등록을 취소합니다.
- IConnectionPointContainer대한 기본 IWMDeviceManager 인터페이스를 쿼리합니다.
- IWMDMNotification 인터페이스에 대한 연결점을 가져옵니다.
- IConnectionPoint::Unadvise호출하여 이벤트 알림에 대한 애플리케이션 등록을 취소하고 이벤트를 수신하도록 등록할 때 받은 고유 ID를 전달합니다.
다음 C++ 코드는 애플리케이션이 닫히면 IWMDMNotification 이벤트에 대한 등록을 취소하는 방법을 보여 줍니다.
HRESULT CWMDMController::UnregisterForNotifications()
{
HRESULT hr = S_FALSE;
// On class initialization, we initialized the handle to -1 as a flag
// to indicate we had not yet registered for notifications. If registration
// never happened, don't bother to unregister.
if (-1 != m_dwNotificationCookie)
{
CComPtr<IConnectionPointContainer> pConxnPointCont;
CComPtr<IConnectionPoint> pIConnPoint;
// Get the connection point container from IWMDeviceManager.
if (SUCCEEDED (hr =
m_IWMDMDeviceMgr->QueryInterface(IID_IConnectionPointContainer,
(void**) & pConxnPointCont)))
{
// Get a connection point from the container.
if (SUCCEEDED (hr = pConxnPointCont->FindConnectionPoint(IID_IWMDMNotification, &pIConnPoint)))
{
// Remove ourselves as a callback from the connection point.
// If successful, reset the ID to a flag value.
if (SUCCEEDED (hr =
pIConnPoint->Unadvise(m_dwNotificationCookie)))
{
m_dwNotificationCookie = -1;
hr = S_OK;
}
}
}
}
return hr;
}
IWMDMProgress 사용하는
Windows Media Device Manager는 콘텐츠 전송, 보안 클록 획득 및 DRM 파일 정보 발생과 같은 특정 작업이 발생할 때 애플리케이션 상태 메시지를 보낼 수 있습니다. 애플리케이션은 이러한 메시지를 사용하여 이벤트의 상태를 모니터링하거나 이벤트를 취소할 수 있습니다. 이 인터페이스를 사용하려면 IWMDMProgress, IWMDMProgress2또는 IWMDMProgress3구현하고 진행률 메시지를 수락하는 메서드에 매개 변수로 전달합니다. IWMDMProgress3 는 추적 중인 작업을 지정하는 식별 GUID를 제공하기 때문에 우수한 인터페이스입니다. 다음 애플리케이션 메서드는 진행률 인터페이스를 허용합니다(해당 서비스 공급자 메서드는 제출된 인터페이스에 알림을 보낼 수 있어야 합니다.)
IWMDMStorageGlobals::Initialize
IWMDRMDeviceApp::AcquireDeviceData
메서드에 인터페이스를 전달하는 예제는 이러한 메서드에 대한 설명서에 제공됩니다. 콜백 인터페이스를 구현하는 예제는 IWMDMProgress, IWMDMProgress2또는 IWMDMProgress3대한 설명서를 참조하세요.