Results 1 to 3 of 3

Thread: Calling external DLL function with Qt

  1. #1
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Calling external DLL function with Qt

    Hi all,
    I bet this is an old question, and I did some research at StackOverflow and Google, however, I ended up more confused.
    How do I simply call a dll function? without linking the dll or other mumbojumbo
    something like:
    Qt Code:
    1. rundll32 USER32.DLL,LockWorkStation
    To copy to clipboard, switch view to plain text mode 
    Thank you.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calling external DLL function with Qt

    To run a dll function you need to link against it, either at compile/link time or at run time. At build time you can configure your linker to link against user32.lib, which will automatically resolve the function for you. You can then just call
    Qt Code:
    1. LockWorkStation()
    To copy to clipboard, switch view to plain text mode 

    If you want to link during run-time, use QLibrary.
    Qt Code:
    1. BOOL (*lockWorkStation)();
    2. ...
    3. QLibrary user32("user32.dll", this);
    4. lockWorkStation = user32.resolve("LockWorkStation");
    5. lockWorkStation();
    To copy to clipboard, switch view to plain text mode 
    Note that the above dry-coded and might contain errors.


    Added after 5 minutes:


    Maybe your suggestion could be done using QProcess:
    Qt Code:
    1. QProcess::execute("rundll32", QStringList("USER32.DLL,LockWorkStation"));
    To copy to clipboard, switch view to plain text mode 
    Last edited by franz; 29th September 2011 at 07:18.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. The following user says thank you to franz for this useful post:

    yaba (30th September 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,671
    Thanks
    13
    Thanked 1,595 Times in 1,523 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Calling external DLL function with Qt

    Any Win32 GUI app is already linked to User32.dll so you should be able to just call LockWorkstation() directly with no extra effort.

  5. The following user says thank you to ChrisW67 for this useful post:

    yaba (30th September 2011)

Similar Threads

  1. Calling external programs via QProcess on Mac OS
    By berliner in forum Qt Programming
    Replies: 13
    Last Post: 15th December 2014, 22:35
  2. Replies: 2
    Last Post: 30th July 2010, 16:59
  3. QtConncurrent - calling function within the class
    By jacek_ in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2009, 18:37
  4. Calling external programs?
    By Hossie in forum Qt Programming
    Replies: 12
    Last Post: 17th May 2008, 18:19
  5. Problems calling C function in C++/Qt class
    By Rayven in forum General Programming
    Replies: 2
    Last Post: 2nd June 2006, 22:32

Tags for this Thread

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.