Results 1 to 2 of 2

Thread: QLibrary, reload DLL

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question QLibrary, reload DLL

    Hello, i'm using QLibrary for loading a DLL on windows.
    I want to unload then reload it after an upate for exemple without leaving the main program.

    It works fine ! but only 4-5 times max before crashing
    I wrote a simple program to illustrate the problem :

    1) the DLL, dll.cpp
    Qt Code:
    1. extern "C" __declspec( dllexport ) int __stdcall fonction( int a, int b )
    2. {
    3. return a+b;
    4. }
    To copy to clipboard, switch view to plain text mode 

    2) the main.cpp
    Qt Code:
    1. #include <QLibrary>
    2. #include <qDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QLibrary myLib("dll");
    7.  
    8. typedef int (*MyPrototype)(int a, int b);
    9.  
    10. for( int i=0; i<4; i++ ) {
    11. MyPrototype myFunction = (MyPrototype) myLib.resolve("fonction");
    12. if (myFunction)
    13. qDebug() << "myFunction=" << myFunction(2,3);
    14. else
    15. qDebug() << "erreur.";
    16. myLib.unload();
    17. }
    18.  
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. myFunction= 5
    2. myFunction= 5
    3. myFunction= 5
    4. myFunction= 5
    5. => Windows display a crash assistant
    To copy to clipboard, switch view to plain text mode 

    Thanks you.
    Last edited by nomprenom; 22nd July 2012 at 16:05.

  2. #2
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary, reload DLL

    I found it comes from the "__stdcall" keyword.
    I forget to add it also in the main program

    Qt Code:
    1. typedef __stdcall int (*MyPrototype)(int a, int b);
    To copy to clipboard, switch view to plain text mode 
    Last edited by nomprenom; 22nd July 2012 at 21:11.

Similar Threads

  1. QLibrary
    By Amita in forum Qt Programming
    Replies: 10
    Last Post: 27th July 2011, 15:35
  2. How to use QLibrary?
    By digog in forum Newbie
    Replies: 22
    Last Post: 5th November 2010, 18:01
  3. Reload a Qt Plugin
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 30th December 2009, 15:36
  4. Reload a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2008, 11:40
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.