PDA

View Full Version : [Question] Calling COM+ (MMDeviceEnumerator and IAudioMeterInformation)



cocus
26th June 2012, 19:12
Hello. Im trying to interface the MMDeviceEnumerator COM.
I've developed a Wrapper class for that interface in VB6 (source is here (http://pastebin.com/3pueKnqE)), and now im trying to get it working in QT.
Now im debugging it, and when it works, I will create a Class.

my MainWindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAxObject>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
QAxObject *MMDevEnum;
QAxObject *IMMDevEnum;
QAxObject *IAudioMeter;
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H



my MainWindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QAxObject>
#include <windows.h>
#include <InitGuid.h>

//#include "endpointvolume.h"

//typedef interface IAudioMeterInformation IAudioMeterInformation;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{

qDebug() << "going to init";

MMDevEnum = new QAxObject(this);
MMDevEnum->setControl("{BCDE0395-E52F-467C-8E3D-C4579291692E}");

qDebug() << "instantiated MMDevEnum";

IMMDevEnum = new QAxObject(this);
IMMDevEnum->setControl("{A95664D2-9614-4F35-A746-DE8DB63617E6}");

IAudioMeter = new QAxObject(this);
IAudioMeter->setControl("{C02216F6-8C67-4B5B-9D00-D008E73E0064}");

MMDevEnum->dynamicCall("GetDefaultAudioEndpoint(0, 0, QAxBase::asVariant)", IMMDevEnum->asVariant());

qDebug() << "OK";

ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}



As you can see, its just a little try.


However, it fails to instantiate IMMDevEnum and IAudioMeter.

In the MSDN, "GetDefaultAudioEndpoint" is defined as:

HRESULT GetDefaultAudioEndpoint(
[in] EDataFlow dataFlow,
[in] ERole role,
[out] IMMDevice **ppDevice
);

/* Example (eRender = 0, eConsole = 0)
In the preceding code fragment, variable hr is of type HRESULT, pDevEnum is a pointer to an IMMDeviceEnumerator interface, and pDeviceOut is a pointer to an IMMDevice interface.
*/
hr = pDevEnum->GetDefaultAudioEndpoint(eRender, eConsole, &pDeviceOut);


Information about Interface IMMDeviceEnumerator can be found in the MSDN here (http://msdn.microsoft.com/en-us/library/windows/desktop/dd371399%28v=vs.85%29.aspx).

I don't know why it doesnt work.

I think that both IMMDevEnum and IAudioMeter doesn´t need to be instantiated, but the Dynamic call still fails: "QAxBase::dynamicCallHelper: Object does not support automation".

Actually I use mingw, not MSVC.

Sorry for my bad english!

Thanks