#ifndef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_LONGHORN
#endif
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwType, dwGetSize, dwSetSize;
// Set String KeyValue
TCHAR *pSetString = _T("Hello Registry");
dwSetSize = _tcslen(pSetString) * sizeof(TCHAR);
RegSetKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestString"), REG_SZ, pSetString, dwSetSize);
// Get String KeyValue
dwGetSize = dwSetSize + sizeof(TCHAR);
TCHAR *pGetString = (TCHAR *)malloc(dwGetSize);
RegGetValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestString"), RRF_RT_ANY, &dwType, pGetString, &dwGetSize);
_tprintf(_T("TestString: %sn"), pGetString);
free(pGetString);
// Delete String KeyValue
RegDeleteKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestString"));
// Set DWORD KeyValue
DWORD dwSetValue = 3;
dwSetSize = sizeof(dwSetValue);
RegSetKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestDWORD"), REG_DWORD, &dwSetValue, dwSetSize);
// Get DWORD KeyValue
DWORD dwGetValue;
dwGetSize = sizeof(dwGetValue);
RegGetValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestDWORD"), RRF_RT_ANY, &dwType, &dwGetValue, &dwGetSize);
_tprintf(_T("TestDWORD: %dn"), dwGetValue);
// Delete DWORD KeyValue
RegDeleteKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestDWORD"));
// Set Binary KeyValue
TCHAR szSetBinary[32] = {_T('H'), _T('e'), _T('l'), _T('l'), _T('o'), _T(' '), _T('R'), _T('e'), _T('g'), _T('i'), _T('s'), _T('t'), _T('r'), _T('y'), _T(' ')};
dwSetSize = 32 * sizeof(TCHAR);
RegSetKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestBinary"), REG_BINARY, szSetBinary, dwSetSize);
// Get Binary KeyValue
TCHAR szGetBinary[32] = {0};
dwGetSize = 32 * sizeof(TCHAR);
RegGetValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestBinary"), RRF_RT_ANY, &dwType, szGetBinary, &dwGetSize);
_tprintf(_T("TestBinary: %sn"), szGetBinary);
// Delete Binary KeyValue
RegDeleteKeyValue(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\TestSubKey\"), _T("TestBinary"));
// Delete SubKey recursively
RegDeleteTree(HKEY_LOCAL_MACHINE, _T("SOFTWARE\TestKey\"));
return 0;
}