❔ ✅ A question for the device of Surface Dial development.
I want to test the codes for surface dail from https://learn.microsoft.com/en-us/windows/apps/design/input/radialcontroller-walkthrough.
The difference is that I want to use a console, while the sample codes use a window and buttons.
The picture shows the error when run my codes.
The error is "System.Exception: "The application invoked an interface that was marshaled for another thread."
How could I debug this problem. Or are there some advice for my coding? thank you!
15 Replies
so, when you use UWP APIs, you need to be careful about APIs with "CreateForCurrentView" or similar in the name
they only work in a UWP app, because it only know how to find the "current view" for a UWP app. you are writing a console app, so that does not work
many of these APIs have an alternative but it requires some extra code:
if you need a RadialControllerConfiguration, it is a similar trick:
after you have created these objects, there should be no more special code required, it should be pretty straightforward. if it still doesn't work, i would guess that it has something to do with this being a console app (you might need a Windows message loop). in this case, it would be simpler to make a windows forms app to try this in
the code would be the same, except of course instead of using
GetConsoleWindow
you would use myForm.Handle
to tell RadialController which window your actions are supposed to be associated withWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity./close
Thank you! I will learn and try. Thank you again!
I tried your solution, using a sample from https://github.com/Microsoft/Windows-classic-samples/tree/main/Samples/RadialController/cs/winforms.
it's not neccessary for RadialControllerMenuItem
I add a method, but it note work. So, is it that this method is not available for RadialControllerMenuItem? How should I do if I want to do some thing when the added menu item is invoked? Thank you !
It seems that the Invoke method is banded to radialControllerMenuItem.
right. that event should just work
apart from creating those two objects--RadialController and RadialControllerConfiguration--everything is the same as UWP
Sorry, I do not understand. It seems that I can not do things when a menu item is selected. For example, I want to run different actions if I add two additional menu items, and they represent different following actions. If the RadialControllerMenuItem can not be get as the RadialController and RadialControllerConfiguration, how should I use the Invoked method?
you make the RadialControllerMenuItem by using
RadialControllerMenuItem.CreateFromIcon
, or one of the other static methods that let you create one
there is no "special" way to create them, it is just the normal way
and you use Invoked like the sample code does to run your code when the button is clickedThank you! I will try. It seems that the RadialControllerMenuItem is not banded to a handle, so it is not need to use the extra codes. Is it right?
right, it does not have the "GetForCurrentView" API which does not work in WinForms. that is what the interop code is working around
Ok! I see. Thank you !
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.!close
Closed!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.