' api_reg.sbp
' Registry Operation

#ifdef UNICODE
Const _FuncName_RegConnectRegistry = "RegConnectRegistryW"
Const _FuncName_RegConnectRegistryEx = "RegConnectRegistryExW"
Const _FuncName_RegCreateKeyEx = "RegCreateKeyExW"
Const _FuncName_RegCreateKeyTransacted = "RegCreateKeyTransactedW"
Const _FuncName_RegDeleteKey = "RegDeleteKeyW"
Const _FuncName_RegDeleteKeyEx = "RegDeleteKeyExW"
Const _FuncName_RegDeleteKeyTransacted = "RegDeleteKeyTransactedW"
Const _FuncName_RegDeleteValue = "RegDeleteValueW"
Const _FuncName_RegEnumKeyEx = "RegEnumKeyExW"
Const _FuncName_RegEnumValue = "RegEnumValueW"
Const _FuncName_RegLoadKey = "RegLoadKeyW"
Const _FuncName_RegOpenKeyEx = "RegOpenKeyExW"
Const _FuncName_RegOpenKeyTransacted = "RegOpenKeyTransactedW"
Const _FuncName_RegQueryInfoKey = "RegQueryInfoKeyW"
Const _FuncName_RegQueryMultipleValues = "RegQueryMultipleValuesW"
Const _FuncName_RegQueryValueEx = "RegQueryValueExW"
Const _FuncName_RegReplaceKey = "RegReplaceKeyW"
Const _FuncName_RegRestoreKey = "RegRestoreKeyW"
Const _FuncName_RegSaveKey = "RegSaveKeyW"
Const _FuncName_RegSetValueEx = "RegSetValueExW"
Const _FuncName_RegUnLoadKey = "RegUnLoadKeyW"
Const _FuncName_RegDeleteKeyValue = "RegDeleteKeyValueW"
Const _FuncName_RegSetKeyValue = "RegSetKeyValueW"
Const _FuncName_RegDeleteTree = "RegDeleteTreeW"
Const _FuncName_RegCopyTree = "RegCopyTreeW"
Const _FuncName_RegGetValue = "RegGetValueW"
Const _FuncName_RegLoadMUIString = "RegLoadMUIStringW"
Const _FuncName_RegLoadAppKey = "RegLoadAppKeyW"
Const _FuncName_RegSaveKeyEx = "RegSaveKeyExW"
#else
Const _FuncName_RegConnectRegistry = "RegConnectRegistryA"
Const _FuncName_RegConnectRegistryEx = "RegConnectRegistryExA"
Const _FuncName_RegCreateKeyEx = "RegCreateKeyExA"
Const _FuncName_RegCreateKeyTransacted = "RegCreateKeyTransactedA"
Const _FuncName_RegDeleteKey = "RegDeleteKeyA"
Const _FuncName_RegDeleteKeyEx = "RegDeleteKeyExA"
Const _FuncName_RegDeleteKeyTransacted = "RegDeleteKeyTransactedA"
Const _FuncName_RegDeleteValue = "RegDeleteValueA"
Const _FuncName_RegEnumKeyEx = "RegEnumKeyExA"
Const _FuncName_RegEnumValue = "RegEnumValueA"
Const _FuncName_RegLoadKey = "RegLoadKeyA"
Const _FuncName_RegOpenKeyEx = "RegOpenKeyExA"
Const _FuncName_RegOpenKeyTransacted = "RegOpenKeyTransactedA"
Const _FuncName_RegQueryInfoKey = "RegQueryInfoKeyA"
Const _FuncName_RegQueryMultipleValues = "RegQueryMultipleValuesA"
Const _FuncName_RegQueryValueEx = "RegQueryValueExA"
Const _FuncName_RegReplaceKey = "RegReplaceKeyA"
Const _FuncName_RegRestoreKey = "RegRestoreKeyA"
Const _FuncName_RegSaveKey = "RegSaveKeyA"
Const _FuncName_RegSetValueEx = "RegSetValueExA"
Const _FuncName_RegUnLoadKey = "RegUnLoadKeyA"
Const _FuncName_RegDeleteKeyValue = "RegDeleteKeyValueA"
Const _FuncName_RegSetKeyValue = "RegSetKeyValueA"
Const _FuncName_RegDeleteTree = "RegDeleteTreeA"
Const _FuncName_RegCopyTree = "RegCopyTreeA"
Const _FuncName_RegGetValue = "RegGetValueA"
Const _FuncName_RegLoadMUIString = "RegLoadMUIStringA"
Const _FuncName_RegLoadAppKey = "RegLoadAppKeyA"
Const _FuncName_RegSaveKeyEx = "RegSaveKeyExA"
#endif

TypeDef REGSAM = Long 'ACCESS_MASK

' Reserved Key Handles
Const HKEY_CLASSES_ROOT =     ((&H80000000 As Long) As ULONG_PTR) As HKEY
Const HKEY_CURRENT_USER =     ((&H80000001 As Long) As ULONG_PTR) As HKEY
Const HKEY_LOCAL_MACHINE =    ((&H80000002 As Long) As ULONG_PTR) As HKEY
Const HKEY_USERS =            ((&H80000003 As Long) As ULONG_PTR) As HKEY
Const HKEY_PERFORMANCE_DATA = ((&H80000004 As Long) As ULONG_PTR) As HKEY
Const HKEY_CURRENT_CONFIG =   ((&H80000005 As Long) As ULONG_PTR) As HKEY
Const HKEY_DYN_DATA =         ((&H80000006 As Long) As ULONG_PTR) As HKEY

Const REG_SECURE_CONNECTION = 1

Type VALENTW
	ve_valuename As PWSTR
	ve_valuelen As DWord
	ve_valueptr As ULONG_PTR
	ve_type As DWord
End Type
Type VALENTA
	ve_valuename As PSTR
	ve_valuelen As DWord
	ve_valueptr As ULONG_PTR
	ve_type As DWord
End Type

#ifdef UNICODE
TypeDef VALENT = VALENTW
#else
TypeDef VALENT = VALENTA
#endif
'------------------------
' Registry API Functions

Declare Function RegCloseKey Lib "advapi32" (hKey As HKEY) As Long
'#if WINVER >= 0x0500 'AB
Declare Function RegOverridePredefKey Lib "advapi32" (hKey As HKEY, hNewKey As HKEY) As Long
Declare Function RegOpenUserClassesRoot Lib "advapi32" (hToken As HANDLE, dwOptions As DWord, samDesired As REGSAM, ByRef hkResult As HKEY) As Long
Declare Function RegOpenCurrentUser Lib "advapi32" (samDesired As REGSAM, ByRef hkResult As HKEY) As Long
Declare Function RegDisablePredefinedCache Lib "advapi32" () As Long
Declare Function RegDisablePredefinedCacheEx Lib "advapi32" () As Long
'#endif
Declare Function RegConnectRegistry Lib "advapi32" Alias _FuncName_RegConnectRegistry (pMachineName As PCTSTR, hKey As HKEY, ByRef hkResult As HKEY) As Long
Declare Function RegConnectRegistryEx Lib "advapi32" Alias _FuncName_RegConnectRegistryEx (lpMachineName As LPCTSTR, hKey As HKEY, Flags As DWord, ByRef hkResult As HKEY) As Long
Declare Function RegCreateKeyEx Lib "advapi32" Alias _FuncName_RegCreateKeyEx (hKey As HKEY, lpSubKey As PCTSTR, Reserved As DWord, lpClass As PTSTR, dwOptions As DWord, samDesired As REGSAM, lpSecurityAttributes As *SECURITY_ATTRIBUTES, ByRef phkResult As HKEY, lpdwDisposition As *DWord) As Long
'#if WINVER >= 0x0600 'AB
Declare Function RegCreateKeyTransacted Lib "advapi32" Alias _FuncName_RegCreateKeyTransacted (hKey As HKEY, lpSubKey As LPCTSTR, Reserved As DWord, lpClass As LPTSTR, dwOptions As DWord, samDesired As REGSAM, lpSecurityAttributes As *SECURITY_ATTRIBUTES, ByRef phkResult As HKEY, lpdwDisposition As *DWord, hTransaction As HANDLE, pExtendedParemeter As VoidPtr) As Long
'#endif
Declare Function RegDeleteKey Lib "advapi32" Alias _FuncName_RegDeleteKey (hKey As HKEY, lpSubKey As PCTSTR) As Long
'#if WINVER >= 0x0520 'AB
Declare Function RegDeleteKeyEx Lib "advapi32" Alias _FuncName_RegDeleteKeyEx (hKey As HKEY, lpSubKey As LPCTSTR, samDesired As REGSAM, Reserved As DWord) As Long
'#endif
'#if WINVER >= 0x0600 'AB
Declare Function RegDeleteKeyTransacted Lib "advapi32" Alias _FuncName_RegDeleteKeyTransacted (hKey As HKEY, lpSubKey As LPCTSTR, samDesired As REGSAM, Reserved As DWord, hTransaction As HANDLE, pExtendedParameter As VoidPtr) As Long
'#endif
'#if WINVER >= 0x0520 'AB
Declare Function RegDisableReflectionKey Lib "advapi32" (hBase As HKEY) As Long
Declare Function RegEnableReflectionKey Lib "advapi32" (hBase As HKEY) As Long
Declare Function RegQueryReflectionKey Lib "advapi32" (hBase As HKEY, ByRef bIsReflectionDisabled As BOOL) As Long
'#endif
Declare Function RegDeleteValue Lib "advapi32" Alias _FuncName_RegDeleteValue (hKey As HKEY, lpValueName As PCTSTR) As Long
Declare Function RegEnumKeyEx Lib "advapi32" Alias _FuncName_RegEnumKeyEx (hKey As HKEY, dwIndex As DWord, pName As PTSTR, ByRef cName As DWord, pReserved As *DWord, pClass As PTSTR, ByRef cClass As DWord, pftLastWriteTime As *FILETIME) As Long
Declare Function RegEnumValue Lib "advapi32" Alias _FuncName_RegEnumValue (hKey As HKEY, dwIndex As DWord, pValueName As PTSTR, ByRef cValueName As DWord, pReserved As *DWord, pType As *DWord, pData As *Byte, pcbData As *DWord) As Long
Declare Function RegFlushKey Lib "advapi32" (hKey As HKEY) As Long
'#if _WIN32_WINNT >= &h0310 'AB
Declare Function RegGetKeySecurity Lib "advapi32" (hKey As HKEY, SecurityInformation As SECURITY_INFORMATION, pSecurityDescriptor As *SECURITY_DESCRIPTOR, ByRef lpcbSecurityDescriptor As DWord) As Long
'#endif
Declare Function RegLoadKey Lib "advapi32" Alias _FuncName_RegLoadKey (hKey As HKEY, pSubKey As PCTSTR, pFile As PCTSTR) As Long
Declare Function RegOpenKeyEx Lib "advapi32" Alias _FuncName_RegOpenKeyEx (hKey As HKEY, lpSubKey As PCTSTR, ulOptions As DWord, samDesired As Long, ByRef phkResult As HKEY) As Long
'#if WINVER >= 0x0600 'AB
Declare Function RegOpenKeyTransacted Lib "advapi32" Alias _FuncName_RegOpenKeyTransacted (hKey As HKEY, lpSubKey As LPCTSTR, ulOptions As DWord, samDesired As REGSAM, ByRef phkResult As HKEY, hTransaction As HANDLE, pExtendedParemeter As VoidPtr) As Long
'#endif
Declare Function RegQueryInfoKey Lib "advapi32" Alias _FuncName_RegQueryInfoKey (hKey As HKEY, pClass As PTSTR, pcClass As *DWord, pReserved As *DWord, pcSubKeys As *DWord, pcMaxSubKeyLen As *DWord, pcMaxClassLen As *DWord, pcValues As *DWord, pcMaxValueNameLen As *DWord, pcMaxValueLen As *DWord, pcbSecurityDescriptor As *DWord, pftLastWriteTime As *FILETIME) As Long
Declare Function RegQueryMultipleValues Lib "advapi32" Alias _FuncName_RegQueryMultipleValues (hKey As HKEY, val_list As *VALENT, num_vals As DWord, pValueBuf As PTSTR, ByRef dwTotsize As DWord) As Long
Declare Function RegQueryValueEx Lib "advapi32" Alias _FuncName_RegQueryValueEx (hKey As HKEY, lpValueName As PCTSTR, lpReserved As DWord, lpType As *DWord, lpData As VoidPtr, lpcbData As *DWord) As Long
Declare Function RegReplaceKey Lib "advapi32" Alias _FuncName_RegReplaceKey (hKey As HKEY, lpSubKey As LPCTSTR, lpNewFile As LPCTSTR, lpOldFile As LPCTSTR) As Long
'#if _WIN32_WINNT >= &h0310 'AB
Declare Function RegRestoreKey Lib "advapi32" Alias _FuncName_RegRestoreKey (hKey As HKEY, lpFile As LPCTSTR, dwFlags As DWord) As Long
'#endif
Declare Function RegSaveKey Lib "advapi32" Alias _FuncName_RegSaveKey (hKey As HKEY, pFile As PCTSTR, pSecurityAttributes As *SECURITY_ATTRIBUTES) As Long
'#if _WIN32_WINNT >= &h0310 'AB
Declare Function RegSetKeySecurity Lib "advapi32" (hKey As HKEY, SecurityInformation As SECURITY_INFORMATION, pSecurityDescriptor As *SECURITY_DESCRIPTOR) AS Long
'#endif
Declare Function RegSetValueEx Lib "advapi32" Alias _FuncName_RegSetValueEx (hKey As HKEY, lpValueName As LPCTSTR, Reserved As DWord, dwType As DWord, lpData As VoidPtr, cbData As DWord) As Long
Declare Function RegUnLoadKey Lib "advapi32" Alias _FuncName_RegUnLoadKey (hKey As HKEY, lpSubKey As LPCTSTR) As Long
'#if _WIN32_WINNT >= &h0600
Declare Function RegDeleteKeyValue Lib "advapi32" Alias _FuncName_RegDeleteKeyValue (hKey As HKEY, lpSubKey As LPCTSTR, lpValueName As LPCTSTR) As Long
Declare Function RegSetKeyValue Lib "advapi32" Alias _FuncName_RegSetKeyValue (hKey As HKEY, lpSubKey As LPCTSTR, lpValueName As LPCTSTR, dwType As DWord, lpData As VoidPtr, cbData As DWord) As Long
Declare Function RegDeleteTree Lib "advapi32" Alias _FuncName_RegDeleteTree (hKey As HKEY, lpSubKey As LPCTSTR) As Long
Declare Function RegCopyTree Lib "advapi32" Alias _FuncName_RegCopyTree (hKeySrc As HKEY, lpSubKey As LPCTSTR, hKeyDest As HKEY) As Long
Declare Function RegGetValue Lib "advapi32" Alias _FuncName_RegGetValue (hKey As HKEY, lpSubKey As LPCTSTR, lpValue As LPCTSTR, dwFlags As DWord, pdwType As *DWord, pvData As VoidPtr, pcbData As *DWord) As Long
Declare Function RegLoadMUIString Lib "advapi32" Alias _FuncName_RegLoadMUIString (hKey As HKEY, pszValue As LPCTSTR, pszOutBuf As LPTSTR, cbOutBuf As DWord, pcbData As *DWord, Flags As DWord, pszDirectory As LPCTSTR) As Long
Declare Function RegLoadAppKey Lib "advapi32" Alias _FuncName_RegLoadAppKey (lpFile As LPCTSTR, ByRef hkResult As HKEY, samDesired As REGSAM, dwOptions As DWord, Reserved As DWord) As Long
'#endif
'#if WINVER >= 0x0510 'AB
Declare Function RegSaveKeyEx Lib "advapi32" Alias _FuncName_RegSaveKeyEx (hKey As HKEY, lpFile As LPCTSTR, lpSecurityAttributes As *SECURITY_ATTRIBUTES, Flags As DWord) As Long
'#endif
