Important: Please read the Qt Code of Conduct -

Particular WinAPI-function "not declared in this scope" - others work. -Qt5.1

  • Hey there,
    Since I use a (static) build of Qt 5.1-beta1 I find myself confronted with strange compiler errors. With previous versions, my program compiled and ran just fine; using the current beta, the compiler seems not to recognise the "[url=]RegDeleteKeyEx()[/url]" function while creating and modifying keys works.
    Now I stumbled upon a limitation in the header "winreg.h":
    #if (WINVER >= 0x0502)

    But since I'm using Windows 7 (and since the program worked fine before) this should actually not be a problem!
    So why does the compiler (MinGW with g++ 4.7.2) suddenly ignore this function and how can I fix it?

    Thanks in advance!

    I created a scary workaround by simply commenting the WINVER-checking lines. However, crippling the compiler's headers doesn't seem to be the way to go...

  • WINVER is not the Windows version your are building on, but the version you are building for.

    RegDeleteKeyExA() simply wasn't available in Windows versions before Windows Vista, so it's correct to disable it for NT versions smaller than 5.02. Note that "Vista" actually is Windows NT 6.0 (NT 5.2 is WindowsXP x64).

    Normally, there should be a file "targetver.h" in your project, that is included before any Win32 API headers and which defines WINVER as desired. So you should adjust the target Windows version there.

    Or just add this line before any Win32 API includes:
    @//Application will run on Vista or later
    #define WINVER 0x0600@

  • Oh, that clears things up!
    It's just funny that I never had to take care of this before.


  • BTW: If you want to make use of newer Win32 API functions and still make your application work on older Windows versions, like Windows XP, you should have a look at the QLibrary class...

  • [quote author="QtFreak" date="1369608160"]It's just funny that I never had to take care of this before.[/quote]
    Microsoft's tools hide this for you by defaulting the target version (WINVER) to a version of their choice. That is probably Windows 7 these days although I have not checked. Last time I checked MingW defaults to Windows 98/NT.

Log in to reply