Pb with RegQueryValueEx 
Author Message
 Pb with RegQueryValueEx

I have written a function which read info from the registry.
This function is using 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

It works fine when i read DWORD types but when i try to read Strings,
RegQueryValueEx doesn't fill lpData out Paramater.

Here's is the code i use in my function:

If (Not (ERROR_SUCCESS = RegOpenKeyEx(hHive, sKey, 0, KEY_READ, hKey))) Then
        Exit Function
    End If

    If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, lType, ByVal
sValue, lValueLen))) Then
        Exit Function
    End If
    If (lType = REG_SZ) Then
        If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_SZ,
ByVal sValue, lValueLen))) Then
            Exit Function
        End If
    End If
    If (lType = REG_DWORD) Then
        If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_DWORD,
lValue, lValueLen))) Then
            Exit Function
        End If
    End If
    RegCloseKey (hKey)

sValue is always "" even when the value in the registry is different of "".


Michel Levy-Provencal
_______________________________________________
Cap Gemini Finance
20 rue Hamelin
75016 Paris (FRANCE)

Tel: 01 47 54 56 63



Tue, 12 Sep 2000 03:00:00 GMT  
 Pb with RegQueryValueEx

I am using the following successfully.

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA"
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long,
ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As
Long

'Get the string value from the registry.
lRetVal = RegQueryValueEx(hKey, strValue, 0, REG_SZ, strRetVal,
lValueLength)

I noticed that the declaration is slightly different and I

Quote:

>I have written a function which read info from the registry.
>This function is using 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

>It works fine when i read DWORD types but when i try to read Strings,
>RegQueryValueEx doesn't fill lpData out Paramater.

>Here's is the code i use in my function:

>If (Not (ERROR_SUCCESS = RegOpenKeyEx(hHive, sKey, 0, KEY_READ, hKey)))
Then
>        Exit Function
>    End If

>    If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, lType, ByVal
>sValue, lValueLen))) Then
>        Exit Function
>    End If
>    If (lType = REG_SZ) Then
>        If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_SZ,
>ByVal sValue, lValueLen))) Then
>            Exit Function
>        End If
>    End If
>    If (lType = REG_DWORD) Then
>        If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_DWORD,
>lValue, lValueLen))) Then
>            Exit Function
>        End If
>    End If
>    RegCloseKey (hKey)

>sValue is always "" even when the value in the registry is different of "".


>Michel Levy-Provencal
>_______________________________________________
>Cap Gemini Finance
>20 rue Hamelin
>75016 Paris (FRANCE)

>Tel: 01 47 54 56 63



Tue, 12 Sep 2000 03:00:00 GMT  
 Pb with RegQueryValueEx

Pour recuperer une chaine a partir des API, celle ci doit dabord etre
initialisee :

Constant BuffLen=512
dim sValue as string
sValue = space$(BuffLen)   -> avant d'avoir mis une valeur dans une chaine,
celle ci n'est pas initialisee
et n'a pas encore d'adresse en memoire.

J'esperes que ca vous aideras,
Gauthier.

Quote:

> I have written a function which read info from the registry.
> This function is using 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

> It works fine when i read DWORD types but when i try to read Strings,
> RegQueryValueEx doesn't fill lpData out Paramater.

> Here's is the code i use in my function:

> If (Not (ERROR_SUCCESS = RegOpenKeyEx(hHive, sKey, 0, KEY_READ, hKey))) Then
>         Exit Function
>     End If

>     If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, lType, ByVal
> sValue, lValueLen))) Then
>         Exit Function
>     End If
>     If (lType = REG_SZ) Then
>         If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_SZ,
> ByVal sValue, lValueLen))) Then
>             Exit Function
>         End If
>     End If
>     If (lType = REG_DWORD) Then
>         If (Not (ERROR_SUCCESS = RegQueryValueEx(hKey, sName, 0, REG_DWORD,
> lValue, lValueLen))) Then
>             Exit Function
>         End If
>     End If
>     RegCloseKey (hKey)

> sValue is always "" even when the value in the registry is different of "".


> Michel Levy-Provencal
> _______________________________________________
> Cap Gemini Finance
> 20 rue Hamelin
> 75016 Paris (FRANCE)

> Tel: 01 47 54 56 63



Tue, 12 Sep 2000 03:00:00 GMT  
 Pb with RegQueryValueEx

This code should allow you to read strings from the registry.  Note that the
API does not function properly and this is the fix that I got off the
Microsoft Support Page.

The items to note are:

1.  You have to send the string for the data to be returned ByVal.  This is
not indicated in the call declaration.

2.  You have to pad the string with the number of characters you want to be
returned.  You can use to small of a string and it will work but it will
truncate the string.

3.  You have to send it a length for the last property (length property).

' Note:  All these functions and constants can be found in the file
winapi32.txt
' This file is access best using the api addin in vb50

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
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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Const glSYNCHRONIZE As Long = &H100000
Public Const glSTANDARD_RIGHTS_ALL As Long = &H1F0000
Public Const glKEY_QUERY_VALUE As Long = &H1
Public Const glKEY_SET_VALUE As Long = &H2
Public Const glKEY_CREATE_SUB_KEY As Long = &H4
Public Const glKEY_ENUMERATE_SUB_KEYS As Long = &H8
Public Const glKEY_NOTIFY As Long = &H10
Public Const glKEY_CREATE_LINK As Long = &H20
Public Const glKEY_ALL_ACCESS As Long = ((glSTANDARD_RIGHTS_ALL Or
glKEY_QUERY_VALUE Or glKEY_SET_VALUE Or _
                                glKEY_CREATE_SUB_KEY Or
glKEY_ENUMERATE_SUB_KEYS Or glKEY_NOTIFY Or _
                                glKEY_CREATE_LINK) And (Not glSYNCHRONIZE))
Public Const glERROR_SUCCESS As Long = 0

Public Const glHKEY_LOCAL_MACHINE As Long = &H80000002

Public Function funGetRegistryString(lKey, sSubKey, sValue) As String

    Dim lDataType As Long
    Dim lDataLength As Long
    Dim sDataString As String * 64 ' Note this can be higher
    Dim lResult As Long
    Dim lHandle As Long

    lDataType = 0
    lDataLength = 64 ' This should equal the length of the string
sDataString

    lResult = RegOpenKeyEx(lKey, sSubKey, 0, glKEY_ALL_ACCESS, lHandle)
    If lResult <> glERROR_SUCCESS Then
        funGetRegistryString = "Error"
        Exit Function
    End If
    lResult = RegQueryValueEx(lHandle, sValue, 0, lDataType, ByVal
sDataString, lDataLength)
    If lResult <> glERROR_SUCCESS Then
        funGetRegistryString = "Error"
        lResult = RegCloseKey(lHandle)
        Exit Function
    End If
    funGetRegistryString = Left(sDataString, lDataLength)
    lResult = RegCloseKey(lHandle)

End Function

Dim sString as string
sString= funGetRegistryString(glHKEY_LOCAL_MACHINE,
"SOFTWARE\IntelliKnit\Server", "Name")



Sun, 17 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Pb with RegQueryValueEx

2. Pb with RegQueryValueEx

3. PB 3.5 / PB 3.2 Libraries

4. Pb of compilation on VB6 with my ocx or pb of compatibility

5. Pb of compilation on VB6 with my ocx or pb of compatibility

6. RegQueryValueEx function

7. RegQueryValueEx API call and NT

8. Registry API - RegQueryValueEx

9. How to call WinApI RegQueryValueEx

10. RegQueryValueEx and hkey_dyn_data

11. RegQueryValueEx problem

12. RegQueryValueEx function and Byte Array Buffers

 

 
Powered by phpBB® Forum Software