PDA

View Full Version : Active Qt. Objects that imported from VirtualBox.tlb could not be instantiated



minskster
13th January 2017, 17:10
Hi Qt Funs!

I have started developing on Qt this week and second day as I stopped on binging VirtualBox COM API to Active Qt.

VirtualBoxClient is created well by non-Active Qt, classic way:


...
#include "d:\sources\algorithms\comtest2\comtest2\debug\virt ualbox.tlh"
...
CLSIDFromProgID(OLESTR("VirtualBox.VirtualBoxClient"), &clsid);
IVirtualBoxClient *virtualBoxClient = nullptr;
hr = CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IVirtualBoxClient), (void**)&virtualBoxClient);
if (FAILED(hr) || virtualBoxClient == nullptr) {
...


But how to do it in Qt style? Step by step:
1) The following lines are added to a project file:
QT += widgets axcontainer
TYPELIBS = $$system(dumpcpp VirtualBox.tlb -n vbox )
vbox.h and vbox.cpp are generated without an error.
2) lines in main.cpp:


#include "vbox.h"

using namespace vbox;


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
vbox::VirtualBox v ;
qDebug() << v.isNull();
vbox::VirtualBoxClient client;
qDebug() << client.isNull();

Output:
CoCreateInstance failure (CoInitialize has not been called.)
QAxBase::setControl: requested control {b1a7a4f2-47b9-4a1e-82b2-07ccd5323c3f} could not be instantiated
true
CoCreateInstance failure (CoInitialize has not been called.)
QAxBase::setControl: requested control {dd3fc71d-26c0-4fe1-bf6f-67f633265bba} could not be instantiated
true

Could you show me the right way?

d_stranz
14th January 2017, 20:54
CoCreateInstance failure (CoInitialize has not been called.)

Read the error message. You need to call CoInitialize() in your code -before- trying to instantiate a COM object. If you look at your "classic way" code, you'll see the call there, too.

ChrisW67
17th January 2017, 16:30
From my reading of http://doc.qt.io/qt-5/activeqt-container.html


QT += axcontainer
TYPELIBS = VirtualBox.tlb
HEADERS += ...
SOURCES += ...
and let qmake organise running dumpcpp.

If you want the namespace vbox then you might need to run dumpcpp once and manually add the two output files to HEADERS and SOURCES and omit the TYPELIBS