PDA

View Full Version : ActiveX interface problem



skyperhh
8th January 2011, 12:33
Hello,

i'm using qt 4.7.1 and MSVC++ 2008.

My problem, i can't connect to any interfaces of the windows media player, by activeX.

Small testprogramm

mediaplayer_simple.pro

TEMPLATE = app
CONFIG += qaxcontainer
HEADERS = playerwindow.h
SOURCES = main.cpp \
playerwindow.cpp


playerwindow.h

#ifndef PLAYERWINDOW_H
#define PLAYERWINDOW_H

#include <QWidget>
class QAxWidget;

class PlayerWindow : public QWidget
{
public:
PlayerWindow();

private:
QAxWidget *wmp;
};

#endif

playerwindow.cpp

#include <QtGui>
#include <QAxWidget>
#include <QAxObject>

#include "playerwindow.h"
#include <windows.h>
#include <wmp.h>

PlayerWindow::PlayerWindow()
{
wmp = new QAxWidget(this);
wmp->setControl("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");
wmp->setProperty("URL", "D:/clock.avi");
qDebug("Version Info: %s", qPrintable(wmp->property("versionInfo").toString()));

IWMPMedia *media;
wmp->queryInterface(QUuid(IID_IWMPMedia), (void **)&media);
if (media)
{
double dur;
media->get_duration(&dur);
qDebug("Duration 2 %f", dur);
media->Release();
}
else
{
qDebug("Failed");
}
}

main.cpp

#include <QApplication>
#include "playerwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PlayerWindow playerWin;
playerWin.show();
return app.exec();
}


Compiling failed, playerwindow.obj:: error: ... extern symbol "_IID_IWMPMedia" in Funktion ""public: __thiscall PlayerWindow::PlayerWindow(void)" (??0PlayerWindow@@QAE@XZ)".

Original german compiler Message -->
Verweis auf nicht aufgelöstes externes Symbol "_IID_IWMPMedia" in Funktion ""public: __thiscall PlayerWindow::PlayerWindow(void)" (??0PlayerWindow@@QAE@XZ)".


Something is wanting by the compiler, but i don't know what.
Anybody an idea?

javimoya
8th January 2011, 12:58
wmp.h is has been generated with dumpcpp?

skyperhh
8th January 2011, 13:27
Hi javimoya,

no, it's from folder of "Microsoft SDKs\Windows\v6.0A\Include ... the Windows SDK include also the windows media player sdk.
I see, i forgot it at the project file ... testing with path in HEADERS to wmp.h fails. :mad:

javimoya
8th January 2011, 15:31
in your initial posted example try this:

1)
add this:
#include <InitGuid.h>

2)
change:
wmp->queryInterface(QUuid(IID_IWMPMedia), (void **)&media);
for:
wmp->queryInterface(QUuid(__uuidof(IWMPMedia)), (void **)&media);

it will compile
:-)

Added after 14 minutes:

anyway the rest of your code is wrong...

try in this way:



wmp->setControl("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");
wmp->setProperty("URL", "C:/Windows/Media/chimes.wav"); // put your video here
QAxObject* currentMedia= wmp->querySubObject("currentMedia");

IWMPMedia *media;
currentMedia->queryInterface(QUuid(__uuidof(IWMPMedia)), (void **)&media);
if (media)
{

double dur;
media->get_duration(&dur);
qDebug("Duration 2 %f", dur);
media->Release();
}
else
{
qDebug("Failed");
}

skyperhh
9th January 2011, 23:46
Hi javimoya,
great work, Thank you very much !!

But, there is also a "small" problem... the values of duration time are zero, did you see the duration time? ... But, I'am thinking, i must wait a little bit and check IWMPCore::get_openState before asking... more tomorrow. :-)



PlayerWindow::PlayerWindow()
{
wmp = new QAxWidget(this);
wmp->setControl("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");
wmp->setProperty("URL", "C:/Windows/Media/notify.wav");

QAxObject* currentMedia = wmp->querySubObject("currentMedia");
//qDebug("Version Info: %s", qPrintable(wmp->property("versionInfo").toString()));

IWMPMedia *media;
currentMedia->queryInterface(QUuid(__uuidof(IWMPMedia)), (void **)&media);
if (media)
{
double dur = 1.0;
HRESULT hr;
hr = media->get_duration(&dur);
if (hr == S_OK)
qDebug("The method succeeded.");
qDebug("Duration %f", dur);

BSTR pbstrDuration;

hr = media->get_durationString(&pbstrDuration);
if (hr == S_OK)
qDebug("The method2 succeeded.");

QString str;
int len = wcslen( pbstrDuration );
str.setUnicode( (QChar*)pbstrDuration, len );

qDebug("Duration string %s", qPrintable(str));

media->Release();
}
else
{
qDebug("Failed");
}
}