Reading registry - problems with LPCWSTR...



  • Hello,

    I'm trying to read the registry, and I've started with this simple example I found:

    @
    #define BUFFER 8192

    #include <QCoreApplication>

    #include <iostream>
    #include <string>
    #include <windows.h>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    char value[255];
    DWORD BufferSize = BUFFER;
    RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "SystemRoot", RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
    std::cout << value << std::endl;
    
    return a.exec&#40;&#41;;
    

    }

    @

    I get the following error:

    cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'LONG RegGetValueW(HKEY, LPCWSTR, LPCWSTR, DWORD, LPDWORD, PVOID, LPDWORD)'

    Now, Google gives me lots of results, but none of them seemed to work / I just don't understand them.. I've tried to play with QString's and LPCWSTR's and stuff with no result. I know the problem has something to do with Unicode, but that's pretty much it. Could anyone push me towards a solution here?



  • Try this way:

    @
    RegGetValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Windows NT\CurrentVersion"), _T("SystemRoot"), RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
    @

    BTW, you can access windows registry using QSettings, see "this":http://qt-project.org/doc/qt-4.8/qsettings.html#accessing-the-windows-registry-directly



  • [quote author="Bogdan" date="1368303529"]Try this way:

    @
    RegGetValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Windows NT\CurrentVersion"), _T("SystemRoot"), RRF_RT_ANY, NULL, (PVOID)&value, &BufferSize);
    @

    BTW, you can access windows registry using QSettings, see "this":http://qt-project.org/doc/qt-4.8/qsettings.html#accessing-the-windows-registry-directly[/quote]

    I actually tried to use QSettings earlier, but didn't get it to work.. Now that I tried it again, I realized that the reason it didn't work, was because I didn't escape the \ -character with another \ -character. So, with QSettings, I know got what I wanted - a stringlist of the keys for given key :) Thank you!


Log in to reply
 

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