1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#If VBA7 Then
' Pour se connecter une base de registre distante
Private Declare PtrSafe Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As LongPtr, phkResult As LongPtr) As Long
' pour énumérer les valeurs d'une clé ouverte
Private Declare PtrSafe Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As LongPtr, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As LongPtr, lpType As Long, lpData As Byte, lpcbData As Long) As Long
' pour énumérer les sous-clé d'une clé ouverte
Private Declare PtrSafe Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As LongPtr, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
'pour ouvrir une clé
Private Declare PtrSafe Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As LongPtr, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As LongPtr) As Long
'pour fermer une clé ouverte
Private Declare PtrSafe Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As LongPtr) As Long
'pour créer une clé
Private Declare PtrSafe Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As LongPtr, ByVal lpSubKey As String, phkResult As LongPtr) As Long
'pour supprimer une clé ouverte
Private Declare PtrSafe Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As LongPtr, ByVal lpSubKey As String) As Long
'pour supprimer une valeur
Private Declare PtrSafe Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As LongPtr, ByVal lpValueName As String) As Long
'pour lire une valeur
' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare PtrSafe Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, lpType As Long, lpData As Any, lpcbData As Long) As Long
'pour fixer ou créer une valeur
' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare PtrSafe Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
#Else
' Pour se connecter une base de registre distante
Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
' pour énumérer les valeurs d'une clé ouverte
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
' pour énumérer les sous-clé d'une clé ouverte
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
'pour ouvrir une clé
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
'pour fermer une clé ouverte
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
'pour créer une clé
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
'pour supprimer une clé ouverte
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
'pour supprimer une valeur
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
'pour lire une valeur
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
'pour fixer ou créer une valeur
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
#End If
' Pas de déclaration du type sur les constantes.
' Pour ne pas se poser la question s'il faut un type Long / LongPtr.
' const prises WINREG.H
Private Const VBREG_HKEY_CLASSES_ROOT = &H80000000
Public Const VBREG_HKEY_CURRENT_USER = &H80000001
Public Const VBREG_HKEY_LOCAL_MACHINE = &H80000002
Private Const VBREG_HKEY_USERS = &H80000003
Private Const VBREG_HKEY_PERFORMANCE_DATA = &H80000004
Private Const VBREG_HKEY_CURRENT_CONFIG = &H80000005
Private Const VBREG_HKEY_DYN_DATA = &H80000006
#If VBA7 Then
Private Function EstBrancheFille(srcMere As String, srcSource As String, srcRecherche As String, Optional Retour As LongPtr) As Boolean
Dim NumBranche As LongPtr
#Else
Private Function EstBrancheFille(srcMere As String, srcSource As String, srcRecherche As String, Optional Retour As Long) As Boolean
Dim NumBranche As Long
#End If
Public Function GetBrancheFille(srcMere As String, srcSource As String, Optional Retour As Variant) As Long
Dim NumBranche As Long
Dim NbBrancheFille As Long
' Numéro de la branche cherchée
NumBranche = Open_a_Key(srcMere, srcSource, VBREG_KEY_ALL_ACCESS)
' Open_a_key retourne un long (car l'api retourne un long quelque soit la plateforme).
' Mais Get_Subkeys attend en paramètre un LongPtr (c'est l'api utilisée qui le demande).
#If VBA7 Then
NbBrancheFille = Get_Subkeys(CLngPtr(NumBranche), Retour)
#Else
NbBrancheFille = Get_Subkeys(NumBranche, Retour)
#End If
GetBrancheFille = NbBrancheFille
End Function |
Partager