GPF in AdvApi32.Dll - Help Anyone?
Quote:
> Here is my problem... I am calling the RegQueryValueEx Function to get
the
> value of a string from the Registry. When I call the function I get a GPF
> in AdvApi32.Dll... Any help.. Here is my calling function.
> Public Function RegStrGet(hKey As Long, lpSubKey As String, lpValueName
As
> String) As String
> Dim lpReserved As Long
> Dim lpType As Long
> Dim lpData As String
> Dim lpcbData As Long
> Dim fSuccess As Long
> lpcbData = 40
> hKey = RegKeyOpen(hKey, lpSubKey)
> fSuccess = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType,
lpData,
> lpcbData)
> If fSuccess = ERROR_SUCCESS Then
> RegStrGet = lpData
> Else
> RegStrGet = "RegStrGet_ERROR: " & fSuccess
> End If
> fSuccess = RegCloseKey(hKey)
> End Function
A friend of mine (sorry Christophe), has write this similar function and it
works fine :
Private Declare Function API_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
Private Declare Function API_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
Private Declare Function API_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
Private Function fRegGetString(hInkey As Long, ByVal strSubKey As String,
ByVal strValName As String, Default As Variant) As Variant
Dim phkResult As Long
Dim strValeur As String * 256
Dim lngValeur As Long
Dim dummy As Long
dummy = API_RegOpenKeyEx(hInkey, strSubKey, 0, KEY_ALL_ACCESS,
phkResult)
If dummy = 0 Then
lngValeur = 256
dummy = API_RegQueryValueEx(phkResult, strValName, 0, REG_SZ, ByVal
strValeur, lngValeur)
If dummy = 0 Then
fRegGetString = Left(strValeur, Len(Trim(strValeur)) - 1)
Else
fRegGetString = Default
Err = dummy
End If
End If
End Function
--
________________________________
Stphane WUCHER - Noisy - FRANCE