locked
How to get native handle from AutoResetEvent?

    Question

  • I'm writing a C# app for both Windows 8.1 and WP 8.1 which will use WASAPI to capture audio. One of the WASAPI calls can take an IntPtr event handle to notify when buffers are ready. However it seems the WinRT version of AutoResetEvent doesn't have the SafeWaitHandle property, so how do I get a native wait handle? Do I need to PInvoke into CreateEventEx, WaitForSingleObject and CloseHandle?
    Thursday, May 29, 2014 2:23 PM

Answers

  • Hi,

    As far as I know, Windows store app cannot get any native operating system handle . Why do you want to get the handle? What's scenario do you want to achieve?

    Best Wishes!

    As I mentioned, I'm using the WASAPI API to capture audio. WASAPI is the official low level audio API for Windows 8.1 and WP 8.1, see this thread. In addition, MS's own C++ sample code for how to use WASAPI in a WinRT app uses CreateEventEx to create the handle.

    So yes, apparently it is perfectly valid to get a native OS handle. It is just that the WinRT .Net classes no longer give you access to the native handle. Kind of a mixed message there, which is part of the confusion.

    Anyway, I ended up creating a wrapper class around CreateEventEx, WaitForSingleObjectEx, SetEvent, ResetEvent and CloseHandle. This solved my problem.

    Friday, May 30, 2014 3:24 PM

All replies

  • Hi,

    As far as I know, Windows store app cannot get any native operating system handle . Why do you want to get the handle? What's scenario do you want to achieve?

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, May 30, 2014 6:57 AM
  • Hi,

    As far as I know, Windows store app cannot get any native operating system handle . Why do you want to get the handle? What's scenario do you want to achieve?

    Best Wishes!

    As I mentioned, I'm using the WASAPI API to capture audio. WASAPI is the official low level audio API for Windows 8.1 and WP 8.1, see this thread. In addition, MS's own C++ sample code for how to use WASAPI in a WinRT app uses CreateEventEx to create the handle.

    So yes, apparently it is perfectly valid to get a native OS handle. It is just that the WinRT .Net classes no longer give you access to the native handle. Kind of a mixed message there, which is part of the confusion.

    Anyway, I ended up creating a wrapper class around CreateEventEx, WaitForSingleObjectEx, SetEvent, ResetEvent and CloseHandle. This solved my problem.

    Friday, May 30, 2014 3:24 PM