PDA

View Full Version : Problem calling CoInitializeEx



OlafSt
6th September 2010, 10:07
Hello there,

first, let me warn you: I'm a very, very, very bloody beginner to all this stuff... I'm used to use Delphi since Version 1 and C++ Builder... I'm not very familiar anymore with giant command lines, using command line tools and so on.

However. I downloaded the Qt-Toolkit from here (http://qt.nokia.com/downloads/sdk-windows-cpp) and installed it. Compiling some of the examples is no Problem, so I went on, to my first simple project.

Here I want to call "CoInitializeEx(...)" - but whatever I try, the result is the same: undefined reference to 'CoInitializeEx@8'. What am I doing wrong ?

Here's my code (don't look too sharp please :)):


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "windows.h"
#include "objbase.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
int DriveMask=0, i=0, j=0;
TCHAR szTemp[512], *p;

ui->setupUi(this);
//Interessanterweise brauchen wir dieses manuelle Connecten gar nicht.
//Wir implementieren einfach einen "on_[ControlName]_[Event]()"-Handler...
//Läßt sich aber abschalten via [ControlName]->setAutoDefault(false);
//connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(pushButtonC licked()));
//pushButton not declared in this scope - wo ist der Button dann ?!?!?
//ui-> ist der Scope, hehe ;-)

//Just for fun ;)
::CoInitializeEx(NULL,1);
//Ermitteln aller Laufwerke und eintragen derselben in die ComboBox
szTemp[0]='\0';
DriveMask=GetLogicalDrives(); j=1;
GetLogicalDriveStrings(511, szTemp);
p=szTemp;
for(i=0;i<26;i++)
{
if ((DriveMask & j) == j)
{
//Lese VolumeLabel aus dem Drive,wenn möglich

}
j <<= 1;
}

}

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

void MainWindow::on_pushButton_clicked()
{
close();
}


And this is the resulting Log when pressing F5 to run this incomplete program:


Führe Build-Schritte für Projekt Test01 aus...
Unveränderte Konfiguration, qmake-Schritt wird übersprungen.
Starte: "D:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `D:/QTProjects/Test01-build-desktop'
D:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/QTProjects/Test01-build-desktop'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\2010.04\qt\include\QtCore" -I"..\..\Qt\2010.04\qt\include\QtGui" -I"..\..\Qt\2010.04\qt\include" -I"..\..\Qt\2010.04\qt\include\ActiveQt" -I"debug" -I"." -I"..\Test01" -I"." -I"..\..\Qt\2010.04\qt\mkspecs\win32-g++" -o debug\mainwindow.o ..\Test01\mainwindow.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\Test01.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"d:\Qt\2010.04\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `D:/QTProjects/Test01-build-desktop'
mingw32-make: Leaving directory `D:/QTProjects/Test01-build-desktop'
debug/mainwindow.o: In function `MainWindow':
D:\QTProjects\Test01-build-desktop/../Test01/mainwindow.cpp:22: undefined reference to `CoInitializeEx@8'
D:\QTProjects\Test01-build-desktop/../Test01/mainwindow.cpp:22: undefined reference to `CoInitializeEx@8'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\Test01.exe] Error 1
mingw32-make: *** [debug] Error 2
The Prozess "D:/Qt/2010.04/mingw/bin/mingw32-make.exe" wurde mit dem Rückgabewert %2 beendet.
Fehler beim Erstellen des Projekts Test01 (Ziel: Desktop)
Beim Ausführen des Build-Schritts 'Make'

Lykurg
6th September 2010, 10:18
Generously I wont comment you comments;) The error results since you probably forget to link the library libole32.a. See LIBS in the qmake documentation. Further you can simply use QFileSystemModel to get the drives instead of using the Windows library.

OlafSt
6th September 2010, 10:39
Thanks a lot, Lykurg !

I tried to modify the LIBS-Entry in my "Makefile-Debug". Without problems I can add -L"d:\Qt\2010.04\qt\mingw\lib". This didn't help. So I also added -llibole32 - no changes. I also tried -llibole32.a, -l"d:\Qt\2010.04\qt\mingw\lib\libole32" and -l"d:\Qt\2010.04\qt\mingw\lib\libole32.a"... All changes with -l result in "No such file or directory".

What must be modified where ? Is it possible to accomplish these changes directly from Qt Creator ?

QFileSystemModel will get its chance, no question. Sooner or later I will have to fight with WinAPI directly and when time has come, I like to have a comment somewhere in my code that shows me how to solve these problems. Just like that comment with "ui->" ;)

Again: Sorry, I'm a very bloody one :mad:

OlafSt
10th September 2010, 08:49
Finally I found the solution.

It is wrong to add "-llibole32". It must be "-lole32" (without "lib").

I found no place, where this is mentioned and figured this out with the help of another forum ;)

/closed