Skip to content

Commit

Permalink
Do not check if the device is created before creating
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <shuanglongchen@yeah.net>
  • Loading branch information
fufesou committed Nov 7, 2023
1 parent 3c301c1 commit 448e627
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions RustDeskIddApp/IddController.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ BOOLEAN GetDevicePath2(

HANDLE DeviceOpenHandle();
VOID DeviceCloseHandle(HANDLE handle);
BOOL DeviceCreateWithLifetimeCheckCreated(BOOL checkCreated, SW_DEVICE_LIFETIME* lifetime, PHSWDEVICE hSwDevice);

void SetLastMsg(const char* format, ...)
{
Expand Down Expand Up @@ -192,12 +191,7 @@ BOOL DeviceCreate(PHSWDEVICE hSwDevice)
return DeviceCreateWithLifetime(SWDeviceLifetimeHandle, NULL);
}

BOOL DeviceCreateWithLifetime(SW_DEVICE_LIFETIME* lifetime, PHSWDEVICE hSwDevice)
{
return DeviceCreateWithLifetimeCheckCreated(TRUE, lifetime, hSwDevice);
}

BOOL DeviceCreateWithLifetimeCheckCreated(BOOL checkCreated, SW_DEVICE_LIFETIME *lifetime, PHSWDEVICE hSwDevice)
BOOL DeviceCreateWithLifetime(SW_DEVICE_LIFETIME *lifetime, PHSWDEVICE hSwDevice)
{
SetLastMsg("Sucess");

Expand All @@ -207,23 +201,13 @@ BOOL DeviceCreateWithLifetimeCheckCreated(BOOL checkCreated, SW_DEVICE_LIFETIME
return FALSE;
}

if (checkCreated == TRUE)
{
BOOL created = TRUE;
if (FALSE == IsDeviceCreated(&created))
{
return FALSE;
}
if (created == TRUE)
{
SetLastMsg("Device is already created, please destroy it first\n");
if (g_printMsg)
{
printf(g_lastMsg);
}
return FALSE;
}
}
// No need to check if the device is previous created.
// https://learn.microsoft.com/en-us/windows/win32/api/swdevice/nf-swdevice-swdevicesetlifetime
// When a client app calls SwDeviceCreate for a software device that was previously marked for
// SwDeviceLifetimeParentPresent, SwDeviceCreate succeeds if there are no open software device handles for the device
// (only one handle can be open for a device). A client app can then regain control over a persistent software device
// for the purposes of updating properties and interfaces or changing the lifetime.
//

// create device
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
Expand Down Expand Up @@ -330,7 +314,7 @@ VOID DeviceClose(HSWDEVICE hSwDevice)
}

HSWDEVICE hSwDevice2 = NULL;
if (DeviceCreateWithLifetimeCheckCreated(FALSE, NULL, &hSwDevice2))
if (DeviceCreateWithLifetime(NULL, &hSwDevice2))
{
if (hSwDevice2 != NULL)
{
Expand Down

0 comments on commit 448e627

Please sign in to comment.