Search code examples
c++windowsregistry

'RegDeleteTree' not declared // Compilation error


I'm trying to delete a windows registry key and all its subkeys, specifically the 'Open with SHCP' key (which I created) and all its subkeys and values. I have the code, but it throws me this error:

'RegDeleteTree' was not declared in this scope

Code:

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

using namespace std;

int main()
{
    HKEY hKey;

    cout << "Deleting Tree:\n\n";
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Classes\\*\\shell", 0, KEY_ALL_ACCESS, &hKey)== ERROR_SUCCESS)
    {
        cout << "Successfully opened key\n";
        if(RegDeleteTree(hKey,"Open with SHCP") == ERROR_SUCCESS)
        {
            cout << "Successfully deleted the key\n";
        }
        else
        {
            cout << "Failed to delete the tree\n";
        }
        RegCloseKey(hKey);
    }
    else
    {
        cout << "Error, no tree available\n";
    }

    cin.get();
    return 0;
}

I'm using Windows 7 and Dev-C++ 5.6.3. Also, I'm able to use other functions like RegOpenKeyEx and RegCreateKeyEx. What am I missing?


Solution

  • You need the SDK for Vista or later, and you need to set _WIN32_WINNT :

    #define  _WIN32_WINNT  0x0600
    #include <Windows.h>
    

    From the MSDN page for RegDeleteTree:

    To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see Using the Windows Headers.