Is it possible to declare a function which takes Win32 event HANDLE as a parameter in idl 3.0 file? - windows-runtime

I am trying to author a set of APIs for my customer.
They need a function which takes Win32 event HANDLE as a parameter for them to wait event via WaitForSingleObject().
However, I cannot find the correct data types for this HANDLE type.
Is it possible to use Win32 event HANDLE in idl 3.0 file?

According to Raymond's comment, the MIDL 3.0 doesn't support HANDLE type and he recommended to use Windows Runtime event instead.
I developed Windows Runtime event following Microsoft's instruction.

Related

Extending the native GamepadAPI?

I'm trying to extend the native GamepadAPI to include custom controller code.
Using TypeScript, I implemented a simple function, to dispatch a "gamepadconnected" event.
// simulate gamepadconnected event
function dispatchGamepadConnectedEvent() {
let gamepad = Object.create(Gamepad.prototype);
console.log(gamepad);
let event = new GamepadEvent('gamepadconnected', {
gamepad: gamepad
})
window.dispatchEvent(event);
console.log('Gamepad connect event dispatched.');
}
However, when dispatching the event, I get an error:
GamepadĀ {}axes: (...)buttons: (...)connected: (...)id: (...)index: (...)mapping: (...)timestamp: (...)vibrationActuator: (...)__proto__: Gamepad
extension.ts:37 Uncaught TypeError: Failed to construct 'GamepadEvent': member gamepad is not of type Gamepad.
at dispatchGamepadConnectedEvent (extension.ts:37)
at extension.ts:48
Even though, the instantiated Gamepad object seems fine, the type of the Gamepad is not correct.
Why is this like that? How can I create a new, proper Gamepad object to fire the native event?
You cannot create a native Gamepad object.
Object.create(Gamepad.prototype) does not create a Gamepad. It creates an object and sets it prototype to Gamepad.prototype. While this trickery often works for application-level APIs, it won't fool native browser APIs.
Your choices are:
Pass null: {gamepad: null}
Pass an actual gamepad reference {gamepad: navigator.getGamepads()[0]}
Dispatch a CustomEvent, not a GamepadEvent.
Try something else entirely.
Not sure about the use case that's behind your question, but one alternative might be to use the WebHID API. I have recently used this API to create a Nintendo Joy-Con driver in JavaScript. If there happen to be reverse engineering efforts for your device in question (hint: check if there is a Linux driver), chances are that you can use this to talk to your device over WebHID.

How to instantiate H264 Encoder on WinRT Store App

I want to be able to encode video frames using Media Foundation IMFTransform for H264 Video Encoding. That's easily doable in Win32, where you can use MFTEnumEx to enumerate the transforms and find the H264 encoder.
However, on WinRT (Store Apps), I can't find a way to instantiate.
I've noticed there's a class CMSH264EncoderMFT, but there's no definition for the CLSID to use on CoCreateInstance.
With:
CoCreateInstance(CLSID_CMSH264EncoderMFT, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IUnknown), (void **)&pUnknown);
CLSID_CMSH264EncoderMFT is undefined for WinRT apps.
And tried:
ComPtr<CMSH264EncoderMFT> encoder = Make<CMSH264EncoderMFT>();
It says the class CMSH264EncoderMFT is incomplete, and says "use of undefined type 'CMSH264EncoderMFT'". Don't even know if the syntax for Make is correct or appropriate...
Does anyone have a clue on how to do this for WinRT?
Use MFCreateSinkWriterFromURL to create a file writer first. Then, use MFCreateMediaType to create an IMFMediaType. Set up its properties, one of which will be the output format: use SetGUID method on the media type with MF_MT_SUBTYPE guid and specify MFVideoFormat_H264 as the argument. Finally, use AddStream method on the sink writer to set the media type to it.
There's an example here (you'll need to modify it a bit when it sets MF_MT_SUBTYPE).
you cannot instantiate object via CMSH264EncoderMFT because it DOES NOT have some interfaces which MUST have object in WinRT for example IInspectable - Provides functionality required for all Windows Runtime classes. CMSH264EncoderMFT IS NOT WinRT class. You can try resolve your task by function MFCreateSinkWriterFromMediaSink - this function takes an object with interface IMFMediaSink. It is possible write code for object with IMFMediaSink interface and receive samples from IMFTransform::ProcessOutput. I just point your attention - you cannot instantiate in WindowsStore code objects which IS NOT Windows Runtime classes.
Regards,
Evgeny Pereguda

WiFiDirect::Close() method is missing in API for C++

I'm writing a C++/CX program that uses WiFiDirect. Target platform version is 10.0.10586.0. Everything works perfectly fine but one thing.
The problem is that there is no WiFiDirect::Close() method available, though it's mentioned in documentation.
The actual error I get is following:
Error C2039 'Close': is not a member of 'Windows::Devices::WiFiDirect::WiFiDirectDevice'
Does anyone know where I can find it?
Close is not projected for C++/CX; it is automatically called when the object's destructor is called (or when no more references are outstanding).
See the docs for IClosable:
Note to callers
Close methods aren't callable through Visual C++ component extensions (C++/CX) on Windows Runtime class instances. Instead, C++/CX code for runtime classes that wants to explicitly clean up a reference should call the destructor or set the last reference to null.

In WinRT MVVM Using Prism how do I listen for a SetProperty notification?

I am using Prism for Windows Runtime to help with my MVVM implementation. It has a built in SetProperty command for properties. How do I listen for a property change from within the View Model to make something else happen?
You can handle INotifyPropertyChanged.PropertyChanged event and check the name of the property. If you want to avoid string comparisons - you can define a new event and raise it for specific property. It can either be a regular CLR event or an EventAggregator one if you want to broadcast it to any interested listeners in the app.

getWindowHandle function doesn't exist for driver in Selenium

I need to implement switch from one window to another in IE. However, element driver doesn't support getWindowHandle function.
I assume it might be just configuration problem or settings, though I don't know how to fix it.
Please, any suggestions.
I'm working with c# - Visual Studio
You haven't said which language bindings you're using, but based on a comment you posted, it looks like you're using C#. The method names are slightly different for each language binding. From this answer:
The object, method, and property names in the .NET language bindings
do not exactly correspond to those in the Java bindings. One of the
principles of the project is that each language binding should "feel
natural" to those comfortable coding in that language.
So you have to do a little translation if you're trying to copy-paste Java code. In this case, you want the combination of the WindowHandles property (to look for the new window handle) and the CurrentWindowHandle property of the driver. You can find full API documentation for the .NET bindings at the project's Google code site.
I am going to make wild guess:
Try to initialize your driver like this:
WebDriver driver = new FirefoxDriver(); //assume you use firefox
The interface WebDriver supports that method. Do not forget to store the handle somewhere ;)
String myWindow = driver.getWindowHandle();
BTW that method should return you actual window If you need all windows you probably should use getWindowHandles() method
If this does not work, please provide more info:
what error exactly are you getting?
How do you initialize WebDriver?
What version of selenium are you using?|
What type of driver are you using?