using WRL to access winRT: where do you find the right names to use for the classfactories and classes?

491 views Asked by At

(This is the next iterative question so I can figure out how to use WRL, after this one was answered I believe correctly.)

So I'm trying to build up to being able to access Bluetooth LE devices through WinRT via WRL.

Continuing in the pattern of a Microsoft example (which is for the uri WinRT class), I am trying at this point just to get the class factory for the DeviceWatcher Class. ( Documentation for that class seems to be here ), this is my pared-down example code:

#include <roapi.h>
#include <combaseapi.h>
#include <iostream>

#include <windows.foundation.h>
#include <windows.foundation.collections.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <stdio.h>

#include <windows.devices.enumeration.h>

using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;

using namespace ABI::Windows::Devices::Enumeration;

int dummy;

ComPtr<IUriRuntimeClassFactory> uriFactory;
ComPtr<IUriRuntimeClass> uri;

ComPtr<IDeviceWatcherRuntimeClassFactory> devWatcherFactory;  //This line produces the only error, "IDeviceWatcherRuntimeClassFactory undefined"
                                                              //(When the line is omitted, the code compiles, links, and produces the smart pointer to a uri class) 
HRESULT hr, hr2, hr3;
    
int main()
{
   
    // Initialize the Windows Runtime.
    RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
  
    // Get the activation factory for the IUriRuntimeClass interface.
    ComPtr<IUriRuntimeClassFactory> uriFactory;
    HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_Uri).Get(), &uriFactory);
  
    // Create a string that represents a URI.
    HString uriHString;
    hr = uriHString.Set(L"http://www.microsoft.com");
   
    // Create the IUriRuntimeClass object.
    ComPtr<IUriRuntimeClass> uri;
    hr2 = uriFactory->CreateUri(uriHString.Get(), &uri);
   

    dummy = 1;    
}

It is the MS example, up to the point of its uri WinRT class construction, and compiles and links and correctly constructs the uri class smart pointer when I leave out my added line that declares the ComPtr for IDeviceWatcherRuntimeClassFactory

The line is my attempt to just create a smart-pointer for the DeviceWatcher class factory, and it fails with identified "IDeviceWatcherRuntimeClassFactory undefined". (It also fails if I use small "d" as the second letter of the type argument.

In using "IDeviceWatcherRuntimeClassFactory", I'm trying to proceed by exact analogy to the MS example.

Besides the MS online documentation for the DeviceWatcher class (3), which doesn't seem to help me, I've also tried looking at what VS2022 solution explorer shows as the expansion of the header windows.devices.enumeration.h (which also does not seem to be telling me what name to use as far as I can figure out).

I've also tried using the VS2022 Object Browser, pointed to a custom component set of all .winmd files in C:\Windows\System32\WinMetaData, and again the information is not helping me, given my level of knowledge.

Can someone give me a sound method, for an arbitrary WinRT class, to figure out the type to use for the smart pointer to the class factory?

And, to save another iteration, once I can make a smart pointer to the factory, I will need to make a smart pointer to the class itself (in my case, to DeviceWatcher). Can someone tell me what exact name to use for the ComPtr type?

Thanks.

0

There are 0 answers