Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] issue with loading dll base address

    General and Desktop
    2
    6
    2333
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      habbas33 last edited by

      hi I want to load dll base address as shown in the code below

      HMODULE g_hDll;
      g_hDll = LoadLibraryW(_T("4FM.dll"));

      when i run it says
      " C:\Qt\UPI_ProIII_062414085021\fpga_lib\sipif.cpp:106: error: C2664: 'HMODULE LoadLibraryW(LPCWSTR)' : cannot convert argument 1 from 'const char [8]' to 'LPCWSTR'
      Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"

      i also tried Qlibrary but i am not able to load on hmodule

      1 Reply Last reply Reply Quote 0
      • H
        habbas33 last edited by

        this works fine when i just run c++ using Visual studio 2010

        1 Reply Last reply Reply Quote 0
        • IamSumit
          IamSumit last edited by

          Hiii.
          Try this

          LPCWSTR is a const char*
          Try
          QString path="4FM.dll";
          std::string str = std::string(path.toAscii().data());
          const char * var = str.c_str();
          LoadLibraryW(var);

          Be Cute

          1 Reply Last reply Reply Quote 0
          • H
            habbas33 last edited by

            not working :(

            C:\Qt\UPI_ProIII_062414085021\fpga_lib\sipif.cpp:108: error: C2039: 'toAscii' : is not a member of 'QString'

            1 Reply Last reply Reply Quote 0
            • IamSumit
              IamSumit last edited by

              [quote author="habbas33" date="1406193293"]not working :(

              C:\Qt\UPI_ProIII_062414085021\fpga_lib\sipif.cpp:108: error: C2039: 'toAscii' : is not a member of 'QString'[/quote]
              use toLatin1() instead of toAscii();
              from Docs.
              http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5

              Be Cute

              1 Reply Last reply Reply Quote 0
              • H
                habbas33 last edited by

                _T() denotes either multi-byte or wide string on Win32 depending on whether or not _UNICODE is #defined. In your case, it must not be. So you have several options here:

                Define _UNICODE. This is application wide, so it may have other consequences for strings in your application.
                Instead of LoadLibraryW(), call LoadLibrary(), which will end up calling LoadLibraryA() behind the scenes if _UNICODE is not defined.
                Instead of using _T("my string"), use L"my string" to force wide characters.
                All of this is explained in some detail over at MSDN.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post