支援具有擴充單位的自動更新事件
重要
本主題中的內容和範例程式碼已過期且目前不受支援。 它可能無法與目前的驅動程式開發工具鏈搭配使用。
本主題包含示範如何支援自動更新事件的範例程式碼。
在應用程式來源中包含下列程式碼,並任意命名為 TestApp.cpp:
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!hEvent)
{
printf("CreateEvent failed\n");
goto errExit;
}
Event.Set = KSEVENTSETID_VIDCAPNotify;
Event.Id = KSEVENT_VIDCAP_AUTO_UPDATE;
Event.Flags = KSEVENT_TYPE_ENABLE;
EventData.NotificationType = KSEVENTF_EVENT_HANDLE;
EventData.EventHandle.Event = hEvent;
EventData.EventHandle.Reserved[0] = 0;
EventData.EventHandle.Reserved[1] = 0;
// register for autoupdate events
hr = m_pKsControl->KsEvent(
&Event,
sizeof(KSEVENT),
&EventData,
sizeof(KSEVENTDATA),
&ulBytesReturned);
if (FAILED(hr))
{
printf("Failed to register for auto-update event : %x\n", hr);
goto errExit;
}
// Wait for event for 5 seconds
dwError = WaitForSingleObject(hEvent, 5000);
// cancel further notifications
hr = m_pKsControl->KsEvent(
NULL,
0,
&EventData,
sizeof(KSEVENTDATA),
&ulBytesReturned);
if (FAILED(hr)) printf("Cancel event returns : %x\n", hr);
if ((dwError == WAIT_FAILED) ||
(dwError == WAIT_ABANDONED) ||
(dwError == WAIT_TIMEOUT))
{
printf("Wait failed : %d\n", dwError);
goto errExit;
}
printf("Wait returned : %d\n", dwError);
// handle the autoupdate event..