0

I have a C++ app built inside OpenKODE environment. Specifically for WinRT platform I need a function, which can tell me if mouse is connected to the machine. I am trying to solve this using Windows Runtime C++ Template Library (WRL) and accessing the MouseCapabilities.MousePresent property. So my code is following (it compiles only for WinRT):

#include <Windows.Foundation.h>
#include <Windows.Devices.Input.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
...
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (FAILED(initialize))
{
    return PrintError(__LINE__, initialize);
}
ComPtr<IMouseCapabilities> mouseCapabilities;
HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Devices_Input_MouseCapabilities).Get(), &mouseCapabilities);
if (FAILED(hr))
{
    return PrintError(__LINE__, hr);
}
INT32 present = 0;
hr = mouseCapabilities->get_MousePresent(&present);
if (FAILED(hr))
{
    return PrintError(__LINE__, hr);
}

But my GetActivationFactory returns failed HRESULT with 0x80004002 (E_NOINTERFACE) code. I am new to WRL or other COM-like libraries, please help me what I did wrong?

2 Answers2

0

What do you mean by "specifically for the WinRT platform"? It looks like you're writing a desktop app, not a Windows Store app--I'm not familiar with it, but I don't see any sign that OpenKODE supports Windows Store apps.

Your code looks superficially correct, but the MouseCapabilities class is available only to Windows Store apps and cannot be instantiated from a desktop app.

Desktop apps can use GetSystemMetrics to detect the mouse (with the same caveat as MouseCapabilities has: drivers can report a non-physical mouse so you can't tell for sure that a physical mouse is connected).

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54
0

For IMouseCapabilities you need to use ActivateInstance instead:

    ComPtr<IMouseCapabilities> caps;
    HRESULT hr = RoActivateInstance(HStringReference(RuntimeClass_Windows_Devices_Input_MouseCapabilities).Get(), &caps);
Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81