Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out async calls to WinRT #97

Closed
timsneath opened this issue Aug 11, 2020 · 4 comments · Fixed by #465
Closed

Figure out async calls to WinRT #97

timsneath opened this issue Aug 11, 2020 · 4 comments · Fixed by #465
Labels
feature New feature or request help wanted Good candidate for others to work on

Comments

@timsneath
Copy link
Contributor

timsneath commented Aug 11, 2020

As an example, this doesn't work yet:
https://github.com/timsneath/win32/blob/main/example/winrt_picker.dart#L20

FileOpenPicker is here:
https://github.com/timsneath/win32/blob/main/lib/src/com/IFileOpenPicker.dart

which is derived using the Windows Runtime metadata using my Dart-based parser (https://pub.dev/packages/winmd).

The original signature is here:
https://docs.microsoft.com/en-us/uwp/api/windows.storage.pickers.fileopenpicker.picksinglefileasync?view=winrt-19041

@timsneath
Copy link
Contributor Author

Here's a Go-based example from @mraleph:
https://github.com/mraleph/go_dart_ffi_example

and more on the general issue:
dart-lang/sdk#37022

@timsneath timsneath added feature New feature or request help wanted Good candidate for others to work on labels Aug 12, 2020
@kennykerr
Copy link

I don't know anything about Dart (yet) 😉 but am the creator of C++/WinRT and more recently started creating Rust/WinRT.

A WinRT async method returns one of four async interfaces (IAsyncXxx). The caller is responsible for either blocking the calling thread until the async object is complete or using some form of coroutine/future, depending on what the language provides, to cooperatively wait for completion. Either way, the caller is notified of completion by providing a delegate implementation that is provided to the async implementation via the Completed property. Obviously, you'll need a way to create WinRT delegates in Dart. Once complete, the caller uses the GetResults method that will either return the successful result of the async object or rethrow/return any error that may have occurred. Both C++/WinRT and Rust/WinRT provide implementations of this pattern for reference. As an example, a C++ blocking call looks something like this:

auto file = picker.PickSingleFileAsync().get();

And C++ coroutines are used for cooperatively waiting (without blocking calling thread):

auto file = co_await picker.PickSingleFileAsync();

Happy to answer any questions you might have: kenny.kerr@microsoft.com

@ghost23
Copy link

ghost23 commented May 14, 2021

I also wanted to know, how async callbacks work for flutter/dart (not necessarily in conjunction with WinRT though). I built a proof of concept here: https://github.com/ghost23/win32_midi

If you're interested, the method in question there is Win32Midi.openMidiInput(...) in ./lib/win32_midi.dart
and its counterpart openMidiInput(...) in ./windows/win32_midi_plugin.cpp, which is taking
an async callback and then answers it in the function MidiInProc in the same file.

Also important is the CallbackManager.h/cpp , which manages the port and the conversion of data from c++ to dart.

@Sunbreak
Copy link
Contributor

@jhancock4d from flutter/flutter#64958 (comment)

You could track the WinRT projection here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature or request help wanted Good candidate for others to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants