Error converting string to LPCTSTR with Qt



  • @Chris-Kawa But for example if i have this function:

    HRSRC res=FindResource(NULL,L"->SetWindowsTextA?",RT_RCDATA);
    

    How i can use SetWindowText? I must to save the result in my variable?. In other words, how i can apply setwindowstext to save in a var and put in my second argument?


  • Moderators

    HRSRC res=FindResource(NULL,L"->SetWindowsTextA?",RT_RCDATA);
    

    That doesn't make any sense whatsoever. SetWindowsText was just an example of WinAPI function since you never said what function you're interested in. Replace it with whatever function you need. If it's FindResource then you can do any of these:

    HRSRC res = FindResourceA(NULL, "SomeResourceName", RT_RCDATA);
    

    or

    HRSRC res = FindResourceW(NULL, L"SomeResourceName", RT_RCDATA);
    

    or

    LPCSTR foo = "SomeResourceName";
    HRSRC res = FindResourceA(NULL, foo, RT_RCDATA);
    

    or

    LPCWSTR foo = L"SomeResourceName";
    HRSRC res = FindResourceW(NULL, foo, RT_RCDATA);
    

    or

    QString foo = "SomeResourceName";
    HRSRC res = FindResourceW(NULL, (LPCWSTR)foo.utf16(), RT_RCDATA);
    

    or any of the dozen other possibilities.



  • @Chris-Kawa said in Error converting string to LPCTSTR with Qt:

    LPCSTR foo = "SomeResourceName";
    HRSRC res = FindResourceA(NULL, foo, RT_RCDATA);

    When i use in qt findresourceA all time take me error i tried the two ways.
    code:

    HRSRC res = FindResourceA(NULL, "SomeResourceName", RT_RCDATA);
    

    error:

    error: C2664: 'HRSRC FindResourceA(HMODULE,LPCSTR,LPCSTR)' : el argumento 3 no puede convertirse de 'LPWSTR' a 'LPCSTR'
    the types are not related; the conversion require reinterpret_cast, conversi¢n of style of C or conversi¢n of style of function
    

    second way:

    LPCSTR foo = "SomeResourceName";
    HRSRC res = FindResourceA(NULL, foo, RT_RCDATA);
    

    error:

    error: C2664: 'HRSRC FindResourceA(HMODULE,LPCSTR,LPCSTR)' : el argumento 3 no puede convertirse de 'LPWSTR' a 'LPCSTR'
    Los tipos se¤alados no est n relacionados; la conversi¢n requiere reinterpret_cast, conversi¢n de estilo de C o conversi¢n de estilo de funci¢n
    

    i can't use the Ansi version with Qt and i dont know why,

    i tried the ex version but not seems to work too:

    LPCSTR foo = "SomeResourceName";
    WORD myVariable;
    HRSRC res = FindResourceExA(NULL, foo, RT_RCDATA,myVariable);
    

    error:

    error: C2664: 'HRSRC FindResourceExA(HMODULE,LPCSTR,LPCSTR,WORD)' : el argumento 3 no puede convertirse de 'LPWSTR' a 'LPCSTR'
    the types are not related; the conversion require reinterpret_cast, conversi¢n of style of C or conversi¢n of style of function
    

  • Qt Champions 2016

    Hi
    Dont it complain about param 3 ?

    error: C2664: 'HRSRC FindResourceA(HMODULE,LPCSTR,LPCSTR)' : el argumento 3 no puede convertirse de 'LPWSTR' a 'LPCSTR'

    so it seems its RT_RCDATA that it barf at ?



  • lol the strange thing this compile

    LPCWSTR foo = L"ELEXE";
    HRSRC res = FindResourceW(NULL, foo, RT_RCDATA);
    

    But obviously return error 1812.
    i tried ansi versión but i can't use it because return me error with the third argument?


  • Qt Champions 2016

    @RIVOPICO

    Here u ask it to use UNICODE version.
    so now it likes RT_RCDATA

    Please go to definition of RT_RCDATA and see what it is.
    Most likely a unicode str.



  • yeah but i tried unicode version and return me error:

    The specified resource name cannot be found in the image file.
    

    So i think with ansi version will be solved. so i will check in the page thanks for your recommendation.


  • Moderators

    RT_RCDATA is a macro that expands to MAKEINTRESOURCE(10), which expands to either MAKEINTRESOURCEA(10) or MAKEINTRESOURCEW(10) when UNICODE is defined or not.
    So just replace RT_RCDATA in my exmples with either MAKEINTRESOURCEA(10) or MAKEINTRESOURCEW(10).



  • @Chris-Kawa Thanks a lot your answer solve my dude thanks a lot. The system of resources of Qt is awesome and more easy to use so it's better. Anyways i was trying to understand more about windows api and with these explications i understand now thanks.


Log in to reply