title: Call RegisterWaitForSingleObject from Python
body: <p>I'm trying to call RegisterWaitForSingleObject on a file handle in Python to check if there's data asynchronously. My understanding is that I can create a callback function in Python, pass it to RegisterWaiForSingleObject, and as soon as there's data to read, the callback function will be called.</p>
  
  <p>Here's my current implementation:</p>
  
  <pre><code>def _decl(name, ret=None, args=(), module=kernel32):
      fn = getattr(module, name)
      fn.restype = ret
      fn.argtypes = args
      return fn
  
  
  WAITORTIMERCALLBACK = ctypes.WINFUNCTYPE(
      None,  # return value: VOID
      ctypes.wintypes.LPVOID,  # PVOID   lpParameter
      ctypes.wintypes.BOOL  # BOOLEAN TimerOrWaitFired
  )
  new_wait_object = HANDLE()
  RegisterWaitForSingleObject = _decl(
      "RegisterWaitForSingleObject", 
      BOOL,
      (ctypes.POINTER(HANDLE), HANDLE, WAITORTIMERCALLBACK, LPVOID, DWORD, DWORD)
  )
  
  def waitortimercallback(lp_parameter, timer_fired):
      print('Data available')
  
  c_waitortimercallback = WAITORTIMERCALLBACK(waitortimercallback)
  
  result = RegisterWaitForSingleObject(
      ctypes.byref(new_wait_object),  # phNewWaitObject
      overlapped.hEvent,  # hObject
      c_waitortimercallback,  # Callback
      None,  # Context
      timeout_mil,  # dwMilliseconds
      0,  # dwFlags
  )
  </code></pre>
  
  <p>I'm not sure I've done everything (or anything) correctly. But I've had success previously with WaitForSingleObject. Unfortunately there are no examples on the internet for RegisterWaitForSingleObject and Python. I probably defined some types incorrectly.</p>
  
  <p>When I run my code, RegisterWaitForSingleObject returns 1 (success), but as soon as data is written, I receive "Segmentation fault" error.</p>
  
  <p>Would appreciate any input.</p>