diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index 9e354cc9f..06d135b02 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -278,7 +278,7 @@ static void* audin_server_thread_func(void* arg) fd = *((void**) buffer); WTSFreeMemory(buffer); - thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); + thread->signals[thread->num_signals++] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd); } /* Wait for the client to confirm that the Audio Input dynamic channel is ready */ diff --git a/channels/rdpsnd/server/rdpsnd.c b/channels/rdpsnd/server/rdpsnd.c index 8e868b6f2..0b499f929 100644 --- a/channels/rdpsnd/server/rdpsnd.c +++ b/channels/rdpsnd/server/rdpsnd.c @@ -175,7 +175,7 @@ static void* rdpsnd_server_thread_func(void* arg) fd = *((void**) buffer); WTSFreeMemory(buffer); - thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); + thread->signals[thread->num_signals++] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd); } s = stream_new(4096); diff --git a/winpr/include/winpr/synch.h b/winpr/include/winpr/synch.h index 02ecb8e95..9a764d98c 100644 --- a/winpr/include/winpr/synch.h +++ b/winpr/include/winpr/synch.h @@ -258,6 +258,8 @@ WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttribu BOOL bManualReset, BOOL bInitialState, int FileDescriptor); WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, int FileDescriptor); +WINPR_API HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, + BOOL bManualReset, BOOL bInitialState, void* pObject); #ifdef UNICODE #define CreateFileDescriptorEvent CreateFileDescriptorEventW diff --git a/winpr/libwinpr/synch/event.c b/winpr/libwinpr/synch/event.c index ac4608386..c0ebca6f2 100644 --- a/winpr/libwinpr/synch/event.c +++ b/winpr/libwinpr/synch/event.c @@ -201,6 +201,23 @@ HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, FileDescriptor); } +/** + * Returns an event based on the handle returned by GetEventWaitObject() + */ +HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, + BOOL bManualReset, BOOL bInitialState, void* pObject) +{ +#ifndef _WIN32 + return CreateFileDescriptorEventW(lpEventAttributes, bManualReset, bInitialState, (int) (ULONG_PTR) pObject); +#else + HANDLE hEvent = NULL; + + DuplicateHandle(GetCurrentProcess(), pObject, GetCurrentProcess(), &hEvent, 0, FALSE, DUPLICATE_SAME_ACCESS); + + return hEvent; +#endif +} + /* * Returns inner file descriptor for usage with select() * This file descriptor is not usable on Windows