Results 1 to 13 of 13

Thread: Linking to Windows DLL

  1. #1
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Linking to Windows DLL

    I need to build an app that uses SQLCipher. I need to link the SQLCipher static lib to a Windows DLL (advapi32.dll) to access the Windows encryption facilities. I'd like to do this all in Qt.

    A) Do I have a ghost of a chance of pulling this off? (I have 40 years programming experience in a dozen different languages but essentially no Windows programming experience.)

    2) Does anyone know where I can get copies of Wincrypt.h and advapi32.lib (which I believe I'd need in order to compile against advapi32.dll)?

    III) Can anyone offer any suggestions to get me started down this crazy path?


    Added after 20 minutes:


    Well, I found my own answer for B: Download the headers and libs section of the Windows SDK.
    Last edited by DanH; 10th April 2011 at 00:35.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linking to Windows DLL

    Not sure what your current question is, I mean, now that you have the libs and headers, what is the problem you are facing now?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Linking to Windows DLL

    Well, mainly I'm wondering about linking to M$ libs in Qt Creator -- whether the compiler and linker can handle it, or if M$ does some things to make it hard/impossible outside of VS. (I'm assuming I'll probably need extern"C" for the interfaces, but do I need anything else?)

    Also, I'm wondering about the library-within-a-library situation -- IIRC there are some restrictions there, with Qt.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking to Windows DLL

    You will find it difficult to link to Visual C-style libraries from MinGW, but if you use VC it will be no problem.

    The IDE (Visual Studio or Qt Creator) doesn't matter as thats just a glorified text editor.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linking to Windows DLL

    Well, mainly I'm wondering about linking to M$ libs in Qt Creator -- whether the compiler and linker can handle it, or if M$ does some things to make it hard/impossible outside of VS.
    Just to add to what squidge said:
    Lib linking to a lib is not a problem, why should it be? the same rules apply.
    You will need extern C if you have C code in your libs yes, but that is standard as well.
    You will be well advised to use the same compiler for all libs, if for some libs you have only the binary and no source, try to find out with which compiler they where built, and build your new libs with that compiler.
    MinGW and VS binaries are not compatible and wont inter-link (AFAIK).
    You can configure Qt Creator to use cl.exe. (the MS compiler).
    If you have the source to all the libs, then you can use any compiler, and just build everything from source with that compiler/linker.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Linking to Windows DLL

    If MinGW can't link to VS libraries, I'm wondering how a MinGW program can communicate with the OS??

    (Bear in mind that the last time I interfaced with the M$ operating system was to port Tiny-C to the PC in the early 80s.)
    Last edited by DanH; 11th April 2011 at 12:46.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linking to Windows DLL

    The one thing has nothing to do with the other.
    VS is using a lib file, or exports file to know the adderess of the exported symbols, when it needs to link while you build.
    MinGW does not.
    But it can be done ("mix linking"):
    http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking to Windows DLL

    Quote Originally Posted by DanH View Post
    If MinGW can't link to VS libraries, I'm wondering how a MinGW program can communicate with the OS??
    Via stub libraries, but if your library is C++ then its going to be difficult. C is more standardised and easier to link to.

  9. #9
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to Windows DLL

    Is it possible to include the dlls in the application itself instead of copying the dlls to the installed folders??? Please say me

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linking to Windows DLL

    Google about static linking, or search for it in the forum.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Linking to Windows DLL

    Well, I've managed to call a couple of Windows Crypto methods from Qt. It took a little song and dance to create the lib.a file, and I still have to create the .h file (and figuring out primitive type equvalence in C/C++ is a bear -- what's a long, what's a long long, what's a dword, etc). But that's just work, after the basic nut is cracked.

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Linking to Windows DLL

    primitive type equvalence in C/C++ is a bear -- what's a long, what's a long long, what's a dword, etc)
    Depends on the IDE you are using, either by hovering you will see the #define expansion, or right click and go to declaration.
    All these types are nothing more than defines based on the basic C++ types - which by they way you can just define in your project if they are not defined.
    Another option is, if your code is only meant for windows, you can just include "windows.h" and you are all sorted out with the windows types.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Linking to Windows DLL

    And, after doing that song and dance, I discovered (by accident) that many of the Windows interfaces, including header files and libs, are already included with MinGW. So the only tricky part is figuring out the type equivalences.

Similar Threads

  1. linking problem under windows
    By grisson in forum General Programming
    Replies: 1
    Last Post: 13th July 2010, 19:11
  2. Replies: 2
    Last Post: 25th November 2009, 23:44
  3. Linking Windows
    By dark1988 in forum Newbie
    Replies: 2
    Last Post: 3rd July 2008, 09:32
  4. Linking QT 3.3 in windows
    By siddharth_univ in forum Installation and Deployment
    Replies: 10
    Last Post: 26th February 2007, 06:38

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.