Hi
My Access project must run on 32 bits & 64 bits and uses registry API. So I turned to How To Use the Registry API to Save and Retrieve Setting for inspiration. And for typing my variables considering the environment, I use DefType command.
My code in a module is as follows:
But when I compile the project, this compilation error message: Type defined by user not defined is displayed due to value returned by the SetValueEx
thanks a lot for your help
My Access project must run on 32 bits & 64 bits and uses registry API. So I turned to How To Use the Registry API to Save and Retrieve Setting for inspiration. And for typing my variables considering the environment, I use DefType command.
My code in a module is as follows:
Code:
#If Win64 Then
DefLngPtr Z
#Else
DefLng Z
#End If
#If Win64 Then
Private Declare PtrSafe Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As LongPtr) As Long
Private Declare PtrSafe Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As LongPtr, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As LongPtr, lpdwDisposition As Long) As LongPtr
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 Long) As LongPtr
Private Declare PtrSafe Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, lpType As Long, ByVal lpData As String, lpcbData As Long) As LongPtr
Private Declare PtrSafe Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, lpType As Long, lpData As Long, lpcbData As Long) As LongPtr
Private Declare PtrSafe Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal lpReserved As LongPtr, lpType As Long, ByVal lpData As Long, lpcbData As Long) As LongPtr
Private Declare PtrSafe Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal Reserved As LongPtr, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As LongPtr
Private Declare PtrSafe Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As LongPtr, ByVal lpValueName As String, ByVal Reserved As LongPtr, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As LongPtr
#Else
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
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
Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
#End If
Public Function SetValueEx(ByVal zhKey, sValueName As String, zlType, vValue As Variant) As z
Dim zlValue
Dim sValue As String
Select Case zlType
Case REG_SZ
sValue = vValue & Chr$(0)
SetValueEx = RegSetValueExString(zhKey, sValueName, 0&, zlType, sValue, Len(sValue))
Case REG_DWORD
zlValue = vValue
SetValueEx = RegSetValueExLong(zhKey, sValueName, 0&, zlType, zlValue, 4)
End Select
End Function
But when I compile the project, this compilation error message: Type defined by user not defined is displayed due to value returned by the SetValueEx
Code:
SetValueEx(ByVal zhKey, sValueName As String, zlType, vValue As Variant) As z
thanks a lot for your help