From ad6c25a3b2f0b4ae43b0cf4cfe6ad9ed376eb214 Mon Sep 17 00:00:00 2001 From: MiroKaku <50670906+MiroKaku@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:09:43 +0800 Subject: [PATCH] fix(core): distinguish the error states of VddAddDisplay. --- core/parsec-vdd.h | 17 +++++++++++------ core/vdd-demo.cc | 11 +++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/parsec-vdd.h b/core/parsec-vdd.h index 8d38644..d9b7f47 100644 --- a/core/parsec-vdd.h +++ b/core/parsec-vdd.h @@ -255,17 +255,22 @@ static const int VDD_MAX_DISPLAYS = 8; // Core IoControl codes, see usage below. typedef enum { - VDD_IOCTL_ADD = 0x0022e004, - VDD_IOCTL_REMOVE = 0x0022a008, - VDD_IOCTL_UPDATE = 0x0022a00c, - VDD_IOCTL_VERSION = 0x0022e010, + VDD_IOCTL_ADD = 0x0022e004, // CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800 + 1, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + VDD_IOCTL_REMOVE = 0x0022a008, // CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800 + 2, METHOD_BUFFERED, FILE_WRITE_ACCESS) + VDD_IOCTL_UPDATE = 0x0022a00c, // CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800 + 3, METHOD_BUFFERED, FILE_WRITE_ACCESS) + VDD_IOCTL_VERSION = 0x0022e010, // CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800 + 4, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + + // new code in driver v0.45 + // relates to IOCTL_UPDATE and per display state + // but unused in Parsec app + VDD_IOCTL_UNKONWN = 0x0022a00c, // CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800 + 5, METHOD_BUFFERED, FILE_WRITE_ACCESS) } VddCtlCode; // Generic DeviceIoControl for all IoControl codes. static DWORD VddIoControl(HANDLE vdd, VddCtlCode code, const void *data, size_t size) { if (vdd == NULL || vdd == INVALID_HANDLE_VALUE) - return 0; + return -1; BYTE InBuffer[32]; ZeroMemory(InBuffer, sizeof(InBuffer)); @@ -285,7 +290,7 @@ static DWORD VddIoControl(HANDLE vdd, VddCtlCode code, const void *data, size_t if (!GetOverlappedResultEx(vdd, &Overlapped, &NumberOfBytesTransferred, 5000, FALSE)) { CloseHandle(Overlapped.hEvent); - return 0; + return -1; } if (Overlapped.hEvent != NULL) diff --git a/core/vdd-demo.cc b/core/vdd-demo.cc index 0629601..7e05a94 100644 --- a/core/vdd-demo.cc +++ b/core/vdd-demo.cc @@ -36,8 +36,6 @@ int main() } }); - updater.detach(); - // Print out guide. printf("Press A to add a virtual display.\n"); printf("Press R to remove the last added.\n"); @@ -53,8 +51,13 @@ int main() case 'a': if (displays.size() < VDD_MAX_DISPLAYS) { int index = VddAddDisplay(vdd); - displays.push_back(index); - printf("Added a new virtual display, index: %d.\n", index); + if (index != -1) { + displays.push_back(index); + printf("Added a new virtual display, index: %d.\n", index); + } + else { + printf("Add virtual display failed."); + } } else { printf("Limit exceeded (%d), could not add more virtual displays.\n", VDD_MAX_DISPLAYS);