[SOLVED] issue with loading dll base address



  • 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



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



  • 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);



  • not working :(

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



  • [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



  • _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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.