hook-helpers.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #if !defined(__cplusplus) && !defined(inline)
  3. #define inline __inline
  4. #endif
  5. #define GC_EVENT_FLAGS (EVENT_MODIFY_STATE | SYNCHRONIZE)
  6. #define GC_MUTEX_FLAGS (SYNCHRONIZE)
  7. static inline HANDLE create_event(const wchar_t *name)
  8. {
  9. return CreateEventW(NULL, false, false, name);
  10. }
  11. static inline HANDLE open_event(const wchar_t *name)
  12. {
  13. return OpenEventW(GC_EVENT_FLAGS, false, name);
  14. }
  15. static inline HANDLE create_mutex(const wchar_t *name)
  16. {
  17. return CreateMutexW(NULL, false, name);
  18. }
  19. static inline HANDLE open_mutex(const wchar_t *name)
  20. {
  21. return OpenMutexW(GC_MUTEX_FLAGS, false, name);
  22. }
  23. static inline HANDLE create_event_plus_id(const wchar_t *name, DWORD id)
  24. {
  25. wchar_t new_name[64];
  26. _snwprintf(new_name, 64, L"%s%lu", name, id);
  27. return create_event(new_name);
  28. }
  29. static inline HANDLE create_mutex_plus_id(const wchar_t *name, DWORD id)
  30. {
  31. wchar_t new_name[64];
  32. _snwprintf(new_name, 64, L"%s%lu", name, id);
  33. return create_mutex(new_name);
  34. }
  35. static inline bool object_signalled(HANDLE event)
  36. {
  37. if (!event)
  38. return false;
  39. return WaitForSingleObject(event, 0) == WAIT_OBJECT_0;
  40. }