Results 1 to 5 of 5

Thread: The problem with QLibrary, help me!

  1. #1
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default The problem with QLibrary, help me!

    I created a small application to use the library:

    Qt Code:
    1. // Test is a simple widget for testing
    2. Test::Test( QWidget* parent): QWidget(parent)
    3. {
    4. setupUi(this);
    5. QByteArray buffer;
    6. QLibrary mylib("kernel32);
    7. typedef int (*GetLocalInfo)( int Locale, int LcType, char* l, int chData);
    8.  
    9. GetLocaleInfor myFunc = (GetLocaleInfo)mylib.resolve("GetLocaleInfoA");
    10.  
    11. if(myFunc(0x400, 0x1003, Buffer.data(), 99) !=0)
    12. {
    13. int v1= 1;
    14. float b2= 2.0;
    15. QString str = "Hi everyone";
    16. QMessageBox::information(0, "Hello","Hello");
    17.  
    18. //...
    19. }
    To copy to clipboard, switch view to plain text mode 

    After the line "QString str = "Hi everyone";", the pointer "this" would be changed the address, I don't know why? If I replace QString by another Object( QTextEdit, QLineEdit...),
    it also changed "this" pointer. After the application changed the address, it display a warnining means that .exe was modified... and stop.

    Could you tell me that way not to change the address?
    Thanks!
    Last edited by jpn; 18th January 2008 at 21:03. Reason: missing [code] tags

  2. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The problem with QLibrary, help me!

    I can't understand very good what do you mean but I see a little mistake in your code:
    QLibrary mylib("kernel32);
    perhaps it must be
    QLibrary mylib("kernel32"); ?

  3. #3
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default Re: The problem with QLibrary, help me!

    Sorry for my mistake( QLibrary mylib("kernel32)) , I mean that when using "myFunc(0x400, 0x1003, Buffer.data(), 99)" function, the address of Test object will be changed( "this" pointer). This is the structure of that small project: main.cpp, test.h and test.cpp. This is very simple project to load a .dll file in Windows. In main.cpp, it only creates an instance of Test.
    In test.h, there are two function: constructor and destructor. If I comment the function:
    myFunc(0x400, 0x1003, Buffer.data(), 99), everything is OK.

    I don't know why?

  4. #4
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default Re: The problem with QLibrary, help me!

    a simple question: how to create a small GUI application with QLibary and load .dll file, may be "kernel32"?

    Do I need any flag, header, library in that application? I use Qt 4.3.3 and Visual Studio 2005.
    In my current program, I don't use and flag, lib in the setting.

    Thanks!

  5. #5
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The problem with QLibrary, help me!

    Why not this way?
    Qt Code:
    1. #include <windows.h>
    2.  
    3. ...
    4.  
    5. // Test is a simple widget for testing
    6. Test::Test( QWidget* parent): QWidget(parent)
    7. {
    8. setupUi(this);
    9. QByteArray buffer;
    10.  
    11. if(GetLocaleInfoA(0x400, 0x1003, Buffer.data(), 99) !=0)
    12. {
    13. int v1= 1;
    14. float b2= 2.0;
    15. QString str = "Hi everyone";
    16. QMessageBox::information(0, "Hello","Hello");
    17.  
    18. //...
    19. }
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 
    And add in pro file LIBS += kernel32.lib?


    By the way, are you sure that buffer.data() is writable? From docs, It seems that with default ctor, QByteArray is empty, so QByteArray::data() is an invalid pointer.

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.