diff options
Diffstat (limited to 'video/IndirectDisplay/IddSampleApp/main.cpp')
| -rw-r--r-- | video/IndirectDisplay/IddSampleApp/main.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/video/IndirectDisplay/IddSampleApp/main.cpp b/video/IndirectDisplay/IddSampleApp/main.cpp new file mode 100644 index 00000000..e1d55ee8 --- /dev/null +++ b/video/IndirectDisplay/IddSampleApp/main.cpp @@ -0,0 +1,93 @@ +#include <iostream> +#include <vector> + +#include <windows.h> +#include <swdevice.h> +#include <conio.h> +#include <wrl.h> + +VOID WINAPI +CreationCallback( + _In_ HSWDEVICE hSwDevice, + _In_ HRESULT hrCreateResult, + _In_opt_ PVOID pContext, + _In_opt_ PCWSTR pszDeviceInstanceId + ) +{ + HANDLE hEvent = *(HANDLE*) pContext; + + SetEvent(hEvent); + UNREFERENCED_PARAMETER(hSwDevice); + UNREFERENCED_PARAMETER(hrCreateResult); + UNREFERENCED_PARAMETER(pszDeviceInstanceId); +} + +int __cdecl main(int argc, wchar_t *argv[]) +{ + UNREFERENCED_PARAMETER(argc); + UNREFERENCED_PARAMETER(argv); + + HANDLE hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); + HSWDEVICE hSwDevice; + SW_DEVICE_CREATE_INFO createInfo = { 0 }; + PCWSTR description = L"Idd Sample Driver"; + + // These match the Pnp id's in the inf file so OS will load the driver when the device is created + PCWSTR instanceId = L"IddSampleDriver"; + PCWSTR hardwareIds = L"IddSampleDriver\0\0"; + PCWSTR compatibleIds = L"IddSampleDriver\0\0"; + + createInfo.cbSize = sizeof(createInfo); + createInfo.pszzCompatibleIds = compatibleIds; + createInfo.pszInstanceId = instanceId; + createInfo.pszzHardwareIds = hardwareIds; + createInfo.pszDeviceDescription = description; + + createInfo.CapabilityFlags = SWDeviceCapabilitiesRemovable | + SWDeviceCapabilitiesSilentInstall | + SWDeviceCapabilitiesDriverRequired; + + // Create the device + HRESULT hr = SwDeviceCreate(L"IddSampleDriver", + L"HTREE\\ROOT\\0", + &createInfo, + 0, + nullptr, + CreationCallback, + &hEvent, + &hSwDevice); + if (FAILED(hr)) + { + printf("SwDeviceCreate failed with 0x%lx\n", hr); + return 1; + } + + // Wait for callback to signal that the device has been created + printf("Waiting for device to be created....\n"); + DWORD waitResult = WaitForSingleObject(hEvent, 10*1000); + if (waitResult != WAIT_OBJECT_0) + { + printf("Wait for device creation failed\n"); + return 1; + } + printf("Device created\n\n"); + + // Now wait for user to indicate the device should be stopped + printf("Press 'x' to exit and destory the software device\n"); + bool bExit = false; + do + { + // Wait for key press + int key = _getch(); + + if (key == 'x' || key == 'X') + { + bExit = true; + } + }while (!bExit); + + // Stop the device, this will cause the sample to be unloaded + SwDeviceClose(hSwDevice); + + return 0; +}
\ No newline at end of file |
