Results 1 to 7 of 7

Thread: Loading a DLL using Qt

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Loading a DLL using Qt

    Hi

    I have created a DLL named firstdll.dll and its written in C. It has only 1 function, named Display(), which i am exporting. When i call that function, it returns a string.

    Now my question is how can I load that dll into my c++ application, so that i can get the string and display it?

    I am trying using LoadLibrary() and other such functions to load the dll but i am not able to make it work. (In C# and VB its not that tough, but since i want to use c++ and Qt, i am finding it very hard to load the dll.)

    I am using this code

    HMODULE hDll = LoadLibrary("firstdll.dll");
    FARPROC fpDisplay = GetProcAddress(hDll, "Display");
    typedef char* (__stdcall *fpDisplayT)();
    fpDisplayT Display = (fpDisplayT)fpDisplay;
    but i get the following error

    Error 1 error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'
    How can i solve this error?

    It would be very helpful if you can give me the complete code to load the dll and then how to retrieve a string that dll returns when called.

    thanks in advance.
    Last edited by srohit24; 24th February 2009 at 09:26.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading a DLL using Qt

    try L"firstdll.dll" instead of "firstdll.dll" in LoadLibrary

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

    srohit24 (24th February 2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Loading a DLL using Qt

    thanks mate, it worked.

    what was the problem??

  5. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading a DLL using Qt

    did u try it? if i remember correctly, it would convert parameter 1 from 'const char [12]' to 'LPCWSTR'

  6. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Loading a DLL using Qt

    yup. I tried it and it worked.

    Now i have a working program in VC++, but i need a Qt version of it, how can I do that?

  7. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading a DLL using Qt

    Have a look at QLibrary

  8. #7
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading a DLL using Qt

    I just thought I'd mention that you're using Win32 API calls which are windows specific.
    The L prefix has something to do with treating the string as Unicode or something, again windows specific. You've probably got Unicode specified in your project settings so the IDE has picked up the unicode version of it's C++ libraries. You're quoted error states 'LoadLibraryW' as having a problem. LoadLibrary is the standard one that takes the standard char set. LoadLibraryW takes a Unicode string, so the L I believe tells the pre-processor to convert this to a unicode string. Another way too fix this error would have been to turn off Unicode under the Project properties dialog, with no need to prefix with the letter L.

    I would say that if you're on QtCentre you're intention is to produce cross platform code, so use QLibrary as suggested by aamer4yu.
    You can still to Qt libraries in VC++, so there's not really any need to prototype a full blown Win32 version prior to going for Qt, unless of course you're testing migration strategies of legacy windows code.

    I hope this provides a little more insight into the monster what is Visual Studio.

Similar Threads

  1. QSplashScreen loading icon
    By talk2amulya in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2009, 09:46
  2. Replies: 1
    Last Post: 28th August 2008, 21:18
  3. QImage not loading successively.
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2008, 13:20
  4. Loading images in html in a QTextBrowser
    By BasicPoke in forum Newbie
    Replies: 1
    Last Post: 6th June 2007, 21:51
  5. QSA: loading scripts at runtime
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 15th February 2006, 15:19

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.