Results 1 to 4 of 4

Thread: Problem calling CoInitializeEx

  1. #1
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem calling CoInitializeEx

    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 ):

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "windows.h"
    4. #include "objbase.h"
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. int DriveMask=0, i=0, j=0;
    11. TCHAR szTemp[512], *p;
    12.  
    13. ui->setupUi(this);
    14. //Interessanterweise brauchen wir dieses manuelle Connecten gar nicht.
    15. //Wir implementieren einfach einen "on_[ControlName]_[Event]()"-Handler...
    16. //Läßt sich aber abschalten via [ControlName]->setAutoDefault(false);
    17. //connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(pushButtonClicked()));
    18. //pushButton not declared in this scope - wo ist der Button dann ?!?!?
    19. //ui-> ist der Scope, hehe ;-)
    20.  
    21. //Just for fun ;)
    22. ::CoInitializeEx(NULL,1);
    23. //Ermitteln aller Laufwerke und eintragen derselben in die ComboBox
    24. szTemp[0]='\0';
    25. DriveMask=GetLogicalDrives(); j=1;
    26. GetLogicalDriveStrings(511, szTemp);
    27. p=szTemp;
    28. for(i=0;i<26;i++)
    29. {
    30. if ((DriveMask & j) == j)
    31. {
    32. //Lese VolumeLabel aus dem Drive,wenn möglich
    33.  
    34. }
    35. j <<= 1;
    36. }
    37.  
    38. }
    39.  
    40. MainWindow::~MainWindow()
    41. {
    42. delete ui;
    43. }
    44.  
    45. void MainWindow::on_pushButton_clicked()
    46. {
    47. close();
    48. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. Führe Build-Schritte für Projekt Test01 aus...
    2. Unveränderte Konfiguration, qmake-Schritt wird übersprungen.
    3. Starte: "D:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
    4. mingw32-make: Entering directory `D:/QTProjects/Test01-build-desktop'
    5. D:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug
    6. mingw32-make[1]: Entering directory `D:/QTProjects/Test01-build-desktop'
    7. 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
    8. 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
    9. mingw32-make[1]: Leaving directory `D:/QTProjects/Test01-build-desktop'
    10. mingw32-make: Leaving directory `D:/QTProjects/Test01-build-desktop'
    11. debug/mainwindow.o: In function `MainWindow':
    12. D:\QTProjects\Test01-build-desktop/../Test01/mainwindow.cpp:22: undefined reference to `CoInitializeEx@8'
    13. D:\QTProjects\Test01-build-desktop/../Test01/mainwindow.cpp:22: undefined reference to `CoInitializeEx@8'
    14. collect2: ld returned 1 exit status
    15. mingw32-make[1]: *** [debug\Test01.exe] Error 1
    16. mingw32-make: *** [debug] Error 2
    17. The Prozess "D:/Qt/2010.04/mingw/bin/mingw32-make.exe" wurde mit dem Rückgabewert %2 beendet.
    18. Fehler beim Erstellen des Projekts Test01 (Ziel: Desktop)
    19. Beim Ausführen des Build-Schritts 'Make'
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem calling CoInitializeEx

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem calling CoInitializeEx

    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

  4. #4
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem calling CoInitializeEx

    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

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:07
  2. Problem calling a routine with dynamicCall
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2010, 17:59
  3. Problem calling stored procedure.. Help!
    By triperzonak in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2010, 08:34
  4. Problem with calling stored procedures in QT
    By sudheer168 in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2009, 09:07
  5. Replies: 1
    Last Post: 30th March 2009, 16:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.