module win32.winreg;

// Translated from Microsoft Platform SDK August 2001 Edition
// by Y.Tomino (demoonlit@inter7.jp)

import win32.winnt, win32.winbase;

// #ifndef _WINREG_
// #define _WINREG_

// #ifdef _MAC
// #...
// #endif

// #ifdef __cplusplus
// extern "C" {
// #endif

// #ifndef WINVER
// #...
// #endif /* !WINVER */

alias ACCESS_MASK REGSAM;

const HKEY HKEY_CLASSES_ROOT = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000000) ;
const HKEY HKEY_CURRENT_USER = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000001) ;
const HKEY HKEY_LOCAL_MACHINE = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000002) ;
const HKEY HKEY_USERS = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000003) ;
const HKEY HKEY_PERFORMANCE_DATA = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000004) ;
const HKEY HKEY_PERFORMANCE_TEXT = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000050) ;
const HKEY HKEY_PERFORMANCE_NLSTEXT = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000060) ;
// #if(WINVER >= 0x0400)
const HKEY HKEY_CURRENT_CONFIG = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000005) ;
const HKEY HKEY_DYN_DATA = cast(HKEY)cast(ULONG_PTR)(cast(LONG)0x80000006) ;

// #ifndef _PROVIDER_STRUCTS_DEFINED
// #define _PROVIDER_STRUCTS_DEFINED

enum : uint { PROVIDER_KEEPS_VALUE_LENGTH = 0x1 }
struct val_context {
  int valuelen;
  LPVOID value_context;
  LPVOID val_buff_ptr;
}

alias val_context* PVALCONTEXT;

struct pvalueA {
  LPSTR pv_valuename;
  int pv_valuelen;
  LPVOID pv_value_context;
  DWORD pv_type;
}
alias pvalueA PVALUEA;
alias pvalueA* PPVALUEA;

struct pvalueW {
  LPWSTR pv_valuename;
  int pv_valuelen;
  LPVOID pv_value_context;
  DWORD pv_type;
}
alias pvalueW PVALUEW;
alias pvalueW* PPVALUEW;

// #ifdef UNICODE
alias PVALUEW PVALUE;
alias PPVALUEW PPVALUE;
// #else
// ...
// #endif // UNICODE

// typedef DWORD _cdecl QUERYHANDLER (LPVOID keycontext, PVALCONTEXT val_list, DWORD num_vals, LPVOID outputbuffer, DWORD FAR *total_outlen, DWORD input_blen);

extern(Windows) alias DWORD function(LPVOID keycontext, PVALCONTEXT val_list, DWORD num_vals, LPVOID outputbuffer, DWORD* total_outlen, DWORD input_blen) PQUERYHANDLER;

struct provider_info {
  PQUERYHANDLER pi_R0_1val;
  PQUERYHANDLER pi_R0_allvals;
  PQUERYHANDLER pi_R3_1val;
  PQUERYHANDLER pi_R3_allvals;
  DWORD pi_flags;
  LPVOID pi_key_context;
}
alias provider_info REG_PROVIDER;

alias provider_info* PPROVIDER;

struct value_entA {
  LPSTR ve_valuename;
  DWORD ve_valuelen;
  DWORD_PTR ve_valueptr;
  DWORD ve_type;
}
alias value_entA VALENTA;
alias value_entA* PVALENTA;

struct value_entW {
  LPWSTR ve_valuename;
  DWORD ve_valuelen;
  DWORD_PTR ve_valueptr;
  DWORD ve_type;
}
alias value_entW VALENTW;
alias value_entW* PVALENTW;

// #ifdef UNICODE
alias VALENTW VALENT;
alias PVALENTW PVALENT;
// #else
// ...
// #endif // UNICODE

// #endif // not(_PROVIDER_STRUCTS_DEFINED)

// #endif /* WINVER >= 0x0400 */

alias NULL WIN31_CLASS;

extern(Windows) export LONG RegCloseKey(
  HKEY hKey);

extern(Windows) export LONG RegOverridePredefKey(
  HKEY hKey,
  HKEY hNewHKey);

extern(Windows) export LONG RegOpenUserClassesRoot(
  HANDLE hToken,
  DWORD dwOptions,
  REGSAM samDesired,
  PHKEY phkResult);

extern(Windows) export LONG RegOpenCurrentUser(
  REGSAM samDesired,
  PHKEY phkResult);

extern(Windows) export LONG RegDisablePredefinedCache();

extern(Windows) export LONG RegConnectRegistryA(
  LPCSTR lpMachineName,
  HKEY hKey,
  PHKEY phkResult);
extern(Windows) export LONG RegConnectRegistryW(
  LPCWSTR lpMachineName,
  HKEY hKey,
  PHKEY phkResult);
// #ifdef UNICODE
alias RegConnectRegistryW RegConnectRegistry;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegCreateKeyA(
  HKEY hKey,
  LPCSTR lpSubKey,
  PHKEY phkResult);
extern(Windows) export LONG RegCreateKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  PHKEY phkResult);
// #ifdef UNICODE
alias RegCreateKeyW RegCreateKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegCreateKeyExA(
  HKEY hKey,
  LPCSTR lpSubKey,
  DWORD Reserved,
  LPSTR lpClass,
  DWORD dwOptions,
  REGSAM samDesired,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  PHKEY phkResult,
  LPDWORD lpdwDisposition);
extern(Windows) export LONG RegCreateKeyExW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  DWORD Reserved,
  LPWSTR lpClass,
  DWORD dwOptions,
  REGSAM samDesired,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  PHKEY phkResult,
  LPDWORD lpdwDisposition);
// #ifdef UNICODE
alias RegCreateKeyExW RegCreateKeyEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegDeleteKeyA(
  HKEY hKey,
  LPCSTR lpSubKey);
extern(Windows) export LONG RegDeleteKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey);
// #ifdef UNICODE
alias RegDeleteKeyW RegDeleteKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegDeleteValueA(
  HKEY hKey,
  LPCSTR lpValueName);
extern(Windows) export LONG RegDeleteValueW(
  HKEY hKey,
  LPCWSTR lpValueName);
// #ifdef UNICODE
alias RegDeleteValueW RegDeleteValue;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegEnumKeyA(
  HKEY hKey,
  DWORD dwIndex,
  LPSTR lpName,
  DWORD cbName);
extern(Windows) export LONG RegEnumKeyW(
  HKEY hKey,
  DWORD dwIndex,
  LPWSTR lpName,
  DWORD cbName);
// #ifdef UNICODE
alias RegEnumKeyW RegEnumKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegEnumKeyExA(
  HKEY hKey,
  DWORD dwIndex,
  LPSTR lpName,
  LPDWORD lpcbName,
  LPDWORD lpReserved,
  LPSTR lpClass,
  LPDWORD lpcbClass,
  PFILETIME lpftLastWriteTime);
extern(Windows) export LONG RegEnumKeyExW(
  HKEY hKey,
  DWORD dwIndex,
  LPWSTR lpName,
  LPDWORD lpcbName,
  LPDWORD lpReserved,
  LPWSTR lpClass,
  LPDWORD lpcbClass,
  PFILETIME lpftLastWriteTime);
// #ifdef UNICODE
alias RegEnumKeyExW RegEnumKeyEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegEnumValueA(
  HKEY hKey,
  DWORD dwIndex,
  LPSTR lpValueName,
  LPDWORD lpcbValueName,
  LPDWORD lpReserved,
  LPDWORD lpType,
  LPBYTE lpData,
  LPDWORD lpcbData);
extern(Windows) export LONG RegEnumValueW(
  HKEY hKey,
  DWORD dwIndex,
  LPWSTR lpValueName,
  LPDWORD lpcbValueName,
  LPDWORD lpReserved,
  LPDWORD lpType,
  LPBYTE lpData,
  LPDWORD lpcbData);
// #ifdef UNICODE
alias RegEnumValueW RegEnumValue;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegFlushKey(
  HKEY hKey);

extern(Windows) export LONG RegGetKeySecurity(
  HKEY hKey,
  SECURITY_INFORMATION SecurityInformation,
  PSECURITY_DESCRIPTOR pSecurityDescriptor,
  LPDWORD lpcbSecurityDescriptor);

extern(Windows) export LONG RegLoadKeyA(
  HKEY hKey,
  LPCSTR lpSubKey,
  LPCSTR lpFile);
extern(Windows) export LONG RegLoadKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  LPCWSTR lpFile);
// #ifdef UNICODE
alias RegLoadKeyW RegLoadKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegNotifyChangeKeyValue(
  HKEY hKey,
  BOOL bWatchSubtree,
  DWORD dwNotifyFilter,
  HANDLE hEvent,
  BOOL fAsynchronus);

extern(Windows) export LONG RegOpenKeyA(
  HKEY hKey,
  LPCSTR lpSubKey,
  PHKEY phkResult);
extern(Windows) export LONG RegOpenKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  PHKEY phkResult);
// #ifdef UNICODE
alias RegOpenKeyW RegOpenKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegOpenKeyExA(
  HKEY hKey,
  LPCSTR lpSubKey,
  DWORD ulOptions,
  REGSAM samDesired,
  PHKEY phkResult);
extern(Windows) export LONG RegOpenKeyExW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  DWORD ulOptions,
  REGSAM samDesired,
  PHKEY phkResult);
// #ifdef UNICODE
alias RegOpenKeyExW RegOpenKeyEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegQueryInfoKeyA(
  HKEY hKey,
  LPSTR lpClass,
  LPDWORD lpcbClass,
  LPDWORD lpReserved,
  LPDWORD lpcSubKeys,
  LPDWORD lpcbMaxSubKeyLen,
  LPDWORD lpcbMaxClassLen,
  LPDWORD lpcValues,
  LPDWORD lpcbMaxValueNameLen,
  LPDWORD lpcbMaxValueLen,
  LPDWORD lpcbSecurityDescriptor,
  PFILETIME lpftLastWriteTime);
extern(Windows) export LONG RegQueryInfoKeyW(
  HKEY hKey,
  LPWSTR lpClass,
  LPDWORD lpcbClass,
  LPDWORD lpReserved,
  LPDWORD lpcSubKeys,
  LPDWORD lpcbMaxSubKeyLen,
  LPDWORD lpcbMaxClassLen,
  LPDWORD lpcValues,
  LPDWORD lpcbMaxValueNameLen,
  LPDWORD lpcbMaxValueLen,
  LPDWORD lpcbSecurityDescriptor,
  PFILETIME lpftLastWriteTime);
// #ifdef UNICODE
alias RegQueryInfoKeyW RegQueryInfoKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegQueryValueA(
  HKEY hKey,
  LPCSTR lpSubKey,
  LPSTR lpValue,
  PLONG lpcbValue);
extern(Windows) export LONG RegQueryValueW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  LPWSTR lpValue,
  PLONG lpcbValue);
// #ifdef UNICODE
alias RegQueryValueW RegQueryValue;
// #else
// #...
// #endif // !UNICODE

// #if(WINVER >= 0x0400)
extern(Windows) export LONG RegQueryMultipleValuesA(
  HKEY hKey,
  PVALENTA val_list,
  DWORD num_vals,
  LPSTR lpValueBuf,
  LPDWORD ldwTotsize);
extern(Windows) export LONG RegQueryMultipleValuesW(
  HKEY hKey,
  PVALENTW val_list,
  DWORD num_vals,
  LPWSTR lpValueBuf,
  LPDWORD ldwTotsize);
// #ifdef UNICODE
alias RegQueryMultipleValuesW RegQueryMultipleValues;
// #else
// #...
// #endif // !UNICODE
// #endif /* WINVER >= 0x0400 */

extern(Windows) export LONG RegQueryValueExA(
  HKEY hKey,
  LPCSTR lpValueName,
  LPDWORD lpReserved,
  LPDWORD lpType,
  LPBYTE lpData,
  LPDWORD lpcbData);
extern(Windows) export LONG RegQueryValueExW(
  HKEY hKey,
  LPCWSTR lpValueName,
  LPDWORD lpReserved,
  LPDWORD lpType,
  LPBYTE lpData,
  LPDWORD lpcbData);
// #ifdef UNICODE
alias RegQueryValueExW RegQueryValueEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegReplaceKeyA(
  HKEY hKey,
  LPCSTR lpSubKey,
  LPCSTR lpNewFile,
  LPCSTR lpOldFile);
extern(Windows) export LONG RegReplaceKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  LPCWSTR lpNewFile,
  LPCWSTR lpOldFile);
// #ifdef UNICODE
alias RegReplaceKeyW RegReplaceKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegRestoreKeyA(
  HKEY hKey,
  LPCSTR lpFile,
  DWORD dwFlags);
extern(Windows) export LONG RegRestoreKeyW(
  HKEY hKey,
  LPCWSTR lpFile,
  DWORD dwFlags);
// #ifdef UNICODE
alias RegRestoreKeyW RegRestoreKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegSaveKeyA(
  HKEY hKey,
  LPCSTR lpFile,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes);
extern(Windows) export LONG RegSaveKeyW(
  HKEY hKey,
  LPCWSTR lpFile,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes);
// #ifdef UNICODE
alias RegSaveKeyW RegSaveKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegSetKeySecurity(
  HKEY hKey,
  SECURITY_INFORMATION SecurityInformation,
  PSECURITY_DESCRIPTOR pSecurityDescriptor);

extern(Windows) export LONG RegSetValueA(
  HKEY hKey,
  LPCSTR lpSubKey,
  DWORD dwType,
  LPCSTR lpData,
  DWORD cbData);
extern(Windows) export LONG RegSetValueW(
  HKEY hKey,
  LPCWSTR lpSubKey,
  DWORD dwType,
  LPCWSTR lpData,
  DWORD cbData);
// #ifdef UNICODE
alias RegSetValueW RegSetValue;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegSetValueExA(
  HKEY hKey,
  LPCSTR lpValueName,
  DWORD Reserved,
  DWORD dwType,
  BYTE* lpData,
  DWORD cbData);
extern(Windows) export LONG RegSetValueExW(
  HKEY hKey,
  LPCWSTR lpValueName,
  DWORD Reserved,
  DWORD dwType,
  BYTE* lpData,
  DWORD cbData);
// #ifdef UNICODE
alias RegSetValueExW RegSetValueEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegUnLoadKeyA(
  HKEY hKey,
  LPCSTR lpSubKey);
extern(Windows) export LONG RegUnLoadKeyW(
  HKEY hKey,
  LPCWSTR lpSubKey);
// #ifdef UNICODE
alias RegUnLoadKeyW RegUnLoadKey;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export BOOL InitiateSystemShutdownA(
  LPSTR lpMachineName,
  LPSTR lpMessage,
  DWORD dwTimeout,
  BOOL bForceAppsClosed,
  BOOL bRebootAfterShutdown);
extern(Windows) export BOOL InitiateSystemShutdownW(
  LPWSTR lpMachineName,
  LPWSTR lpMessage,
  DWORD dwTimeout,
  BOOL bForceAppsClosed,
  BOOL bRebootAfterShutdown);
// #ifdef UNICODE
alias InitiateSystemShutdownW InitiateSystemShutdown;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export BOOL AbortSystemShutdownA(
  LPSTR lpMachineName);
extern(Windows) export BOOL AbortSystemShutdownW(
  LPWSTR lpMachineName);
// #ifdef UNICODE
alias AbortSystemShutdownW AbortSystemShutdown;
// #else
// #...
// #endif // !UNICODE

// inline #include <reason.h>
// ----

// #if !defined SENTINEL_Reason
// # define SENTINEL_Reason

enum : uint { SHTDN_REASON_FLAG_COMMENT_REQUIRED = 0x01000000 }
enum : uint { SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED = 0x02000000 }
enum : uint { SHTDN_REASON_FLAG_CLEAN_UI = 0x04000000 }
enum : uint { SHTDN_REASON_FLAG_DIRTY_UI = 0x08000000 }

enum : uint { SHTDN_REASON_FLAG_USER_DEFINED = 0x40000000 }
enum : uint { SHTDN_REASON_FLAG_PLANNED = 0x80000000 }

enum : uint { SHTDN_REASON_MAJOR_OTHER = 0x00000000 }
enum : uint { SHTDN_REASON_MAJOR_NONE = 0x00000000 }
enum : uint { SHTDN_REASON_MAJOR_HARDWARE = 0x00010000 }
enum : uint { SHTDN_REASON_MAJOR_OPERATINGSYSTEM = 0x00020000 }
enum : uint { SHTDN_REASON_MAJOR_SOFTWARE = 0x00030000 }
enum : uint { SHTDN_REASON_MAJOR_APPLICATION = 0x00040000 }
enum : uint { SHTDN_REASON_MAJOR_SYSTEM = 0x00050000 }
enum : uint { SHTDN_REASON_MAJOR_POWER = 0x00060000 }

enum : uint { SHTDN_REASON_MINOR_OTHER = 0x00000000 }
enum : uint { SHTDN_REASON_MINOR_NONE = 0x000000ff }
enum : uint { SHTDN_REASON_MINOR_MAINTENANCE = 0x00000001 }
enum : uint { SHTDN_REASON_MINOR_INSTALLATION = 0x00000002 }
enum : uint { SHTDN_REASON_MINOR_UPGRADE = 0x00000003 }
enum : uint { SHTDN_REASON_MINOR_RECONFIG = 0x00000004 }
enum : uint { SHTDN_REASON_MINOR_HUNG = 0x00000005 }
enum : uint { SHTDN_REASON_MINOR_UNSTABLE = 0x00000006 }
enum : uint { SHTDN_REASON_MINOR_DISK = 0x00000007 }
enum : uint { SHTDN_REASON_MINOR_PROCESSOR = 0x00000008 }
enum : uint { SHTDN_REASON_MINOR_NETWORKCARD = 0x00000009 }
enum : uint { SHTDN_REASON_MINOR_POWER_SUPPLY = 0x0000000a }
enum : uint { SHTDN_REASON_MINOR_CORDUNPLUGGED = 0x0000000b }
enum : uint { SHTDN_REASON_MINOR_ENVIRONMENT = 0x0000000c }
enum : uint { SHTDN_REASON_MINOR_HARDWARE_DRIVER = 0x0000000d }
enum : uint { SHTDN_REASON_MINOR_OTHERDRIVER = 0x0000000e }
enum : uint { SHTDN_REASON_MINOR_BLUESCREEN = 0x0000000F }

alias SHTDN_REASON_MINOR_NONE SHTDN_REASON_UNKNOWN;

enum : uint { SHTDN_REASON_VALID_BIT_MASK = 0xc0ffffff }

enum : uint { PCLEANUI = SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_FLAG_CLEAN_UI }
enum : uint { UCLEANUI = SHTDN_REASON_FLAG_CLEAN_UI }
enum : uint { UDIRTYUI = SHTDN_REASON_FLAG_DIRTY_UI }

enum : uint { MAX_REASON_NAME_LEN = 64 }
enum : uint { MAX_REASON_DESC_LEN = 256 }
enum : uint { MAX_REASON_BUGID_LEN = 32 }
enum : uint { MAX_REASON_COMMENT_LEN = 4096 }

// #endif // !defined SENTINEL_Reason
// ----

enum : uint { REASON_SWINSTALL = SHTDN_REASON_MAJOR_SOFTWARE | SHTDN_REASON_MINOR_INSTALLATION }
enum : uint { REASON_HWINSTALL = SHTDN_REASON_MAJOR_HARDWARE | SHTDN_REASON_MINOR_INSTALLATION }
enum : uint { REASON_SERVICEHANG = SHTDN_REASON_MAJOR_SOFTWARE | SHTDN_REASON_MINOR_HUNG }
enum : uint { REASON_UNSTABLE = SHTDN_REASON_MAJOR_SYSTEM | SHTDN_REASON_MINOR_UNSTABLE }
enum : uint { REASON_SWHWRECONF = SHTDN_REASON_MAJOR_SOFTWARE | SHTDN_REASON_MINOR_RECONFIG }
enum : uint { REASON_OTHER = SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER }
alias SHTDN_REASON_UNKNOWN REASON_UNKNOWN;
alias SHTDN_REASON_FLAG_PLANNED REASON_PLANNED_FLAG;

extern(Windows) export BOOL InitiateSystemShutdownExA(
  LPSTR lpMachineName,
  LPSTR lpMessage,
  DWORD dwTimeout,
  BOOL bForceAppsClosed,
  BOOL bRebootAfterShutdown,
  DWORD dwReason);
extern(Windows) export BOOL InitiateSystemShutdownExW(
  LPWSTR lpMachineName,
  LPWSTR lpMessage,
  DWORD dwTimeout,
  BOOL bForceAppsClosed,
  BOOL bRebootAfterShutdown,
  DWORD dwReason);
// #ifdef UNICODE
alias InitiateSystemShutdownExW InitiateSystemShutdownEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG RegSaveKeyExA(
  HKEY hKey,
  LPCSTR lpFile,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD Flags);
extern(Windows) export LONG RegSaveKeyExW(
  HKEY hKey,
  LPCWSTR lpFile,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD Flags);
// #ifdef UNICODE
alias RegSaveKeyExW RegSaveKeyEx;
// #else
// #...
// #endif // !UNICODE

extern(Windows) export LONG Wow64Win32ApiEntry(
  DWORD dwFuncNumber,
  DWORD dwFlag,
  DWORD dwRes);

// #ifdef __cplusplus
// }
// #endif

// #endif // _WINREG_

