With C++/WinRT the AudioGraphSettings
can be easily initialized with its constructor:
AudioGraphSettings settings(AudioRenderCategory::Media);
I'm having trouble to use it inside my WRL project. Below is my implementation
ComPtr<IAudioGraphSettings> settings;
Windows::Foundation::GetActivationFactory(
HStringReference(RuntimeClass_Windows_Media_Audio_AudioGraphSettings).Get(),
&settings
);
The settings
still null and I don't know how to initialize it with the required AudioRenderCategory
constructor.
If I do it like below, I got access violation crash because it's still null.
settings->put_AudioRenderCategory(AudioRenderCategory::AudioRenderCategory_Media);
Type activation at the ABI level is more involved than, for example, instantiating types in C++. The admittedly terse documentation outlines the different mechanisms:
The
IAudioGraphSettings
type falls into the second category: It instantiates a type based on a single argument of typeAudioRenderCategory
. Instantiating a type is thus a two-phase process:The code in the question conflates both operations, and the call to
GetActivationFactory
returns anHRESULT
value of 0x80004002, i.e.E_NOINTERFACE
. It needs to request theIAudioGraphSettingsFactory
interface instead, and subsequently use that factory to instantiate theIAudioGraphSettings
type.The following is a complete implementation that illustrates how to activate an
IAudioGraphSettings
type:This is how things look at the ABI level, which is ultimately where the WRL lives. C++/WinRT takes care of all the boilerplate code, and neatly maps parameterized factory activation onto C++ constructor implementations. That's why the C++/WinRT implementation is so much more compact.