Answered by:
IActivateAudioInterfaceCompletionHandler in a CX ref class

Question
-
Hi all,
I am trying to make a Windows Runtime Component for Universal app (Windows/Windows Phone 8.1) that handles capture/render streams from WASAPI. I know there are few samples out there, but I have the Windows Phone 8 code and want to port it. All I need is to implement the activation of the device with ActivateAudioInterfaceAsync. Not very C++ guy, so, I've stumbled upon a problem - cannot wrap my mind around how I shall implement IActivateAudioInterfaceCompletionHandler interface in the ref class.
The following does not compile (I know I do not have the interface method implemented, but still, the error seems strange) - "error C2811: 'WasapiAudioComp::Class1' : cannot inherit from 'IActivateAudioInterfaceCompletionHandler', a ref class can only inherit from a ref class or interface class"
#pragma once #include <mmdeviceapi.h> namespace WasapiAudioComp { public ref class Class1 sealed : IActivateAudioInterfaceCompletionHandler { public: Class1(); }; }
I know of all the shiny examples out there that have some alien RuntimeClass<> and WRL, but I wonder what I'm doing wrong? I also see some examples like http://www.codeproject.com/Tips/713756/Activating-WRL-Audio-Interfaces-in-Native-Cplusplu, but that looks even more scary that the RuntimeClass stuff.
Visual Studio 2013, Universal App, Windows Runtime Component :)
Thanks in advance,
KamenFriday, February 13, 2015 10:49 AM
Answers
-
The compilation error pretty much says it all.
Here is how you can work around this limitation.
Suppose this is where you want to handle the event
public ref class MyHandler sealed { public: void MyCompleteHandler() {};
private:
MyNativeHandler* _nativeHandler; };
Use a native class as a member which derives from the callback interface
class MyNativeHandler :IActivateAudioInterfaceCompletionHandler {
public:
MyNativeHandler(AudioRenderer^ owner)
{
_owner=owner;
} public: //IActivateAudioInterfaceCompletionHandler STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *op) { if(owner!=nullptr) { owner->ActualHandler(); } }; private: MyHandler ^ _owner; };
set up these two classes correctly, now you can have a ref class to handle native callbcks
- Marked as answer by Kamka Monday, February 16, 2015 1:03 PM
Monday, February 16, 2015 3:12 AM
All replies
-
Hi Kamen,
Thanks for posting on the forum, I would like find our senior engineers help you with your issue. It may take some time and thanks for your understanding. :)
--James
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Monday, February 16, 2015 1:52 AMModerator -
The compilation error pretty much says it all.
Here is how you can work around this limitation.
Suppose this is where you want to handle the event
public ref class MyHandler sealed { public: void MyCompleteHandler() {};
private:
MyNativeHandler* _nativeHandler; };
Use a native class as a member which derives from the callback interface
class MyNativeHandler :IActivateAudioInterfaceCompletionHandler {
public:
MyNativeHandler(AudioRenderer^ owner)
{
_owner=owner;
} public: //IActivateAudioInterfaceCompletionHandler STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *op) { if(owner!=nullptr) { owner->ActualHandler(); } }; private: MyHandler ^ _owner; };
set up these two classes correctly, now you can have a ref class to handle native callbcks
- Marked as answer by Kamka Monday, February 16, 2015 1:03 PM
Monday, February 16, 2015 3:12 AM -
Great, thanks a million!Monday, February 16, 2015 1:04 PM