win-capture: Add hook helper functions for IPC

These inline functions simplify the process of using windows IPC
objects, such as mutexes and events.
master
jp9000 2014-11-10 01:48:16 -08:00
parent 46aeb46757
commit 6ece794334
2 changed files with 47 additions and 0 deletions

View File

@ -2,6 +2,7 @@ project(win-capture)
set(win-capture_HEADERS
obfuscate.h
hook-helpers.h
window-helpers.h
dc-capture.h)

View File

@ -0,0 +1,46 @@
#pragma once
#if !defined(__cplusplus) && !defined(inline)
#define inline __inline
#endif
static inline HANDLE get_event(const char *name)
{
HANDLE event = CreateEventA(NULL, false, false, name);
if (!event)
event = OpenEventA(EVENT_ALL_ACCESS, false, name);
return event;
}
static inline HANDLE get_mutex(const char *name)
{
HANDLE event = CreateMutexA(NULL, false, name);
if (!event)
event = OpenMutexA(MUTEX_ALL_ACCESS, false, name);
return event;
}
static inline HANDLE get_event_plus_id(const char *name, DWORD id)
{
char new_name[64];
sprintf(new_name, "%s%d", name, id);
return get_event(new_name);
}
static inline HANDLE get_mutex_plus_id(const char *name, DWORD id)
{
char new_name[64];
sprintf(new_name, "%s%d", name, id);
return get_mutex(new_name);
}
static inline bool object_signalled(HANDLE event)
{
if (!event)
return false;
return WaitForSingleObject(event, 0) == WAIT_OBJECT_0;
}