Get Binary Values (and others) from the Registry (32bit, 20 mar 1998))

Back Up Next

Author: Eric Aling
Accessed:
Download: Download regquery.zip ( regquery.zip 10Kb )

Okay, you can get values from the registry with PB5 and 6 but not all, especially binary values. Using the Windows API functions, it is possible to get them. This pibble shows you how it is done. In fact, only three API functions are needed. One, to open the specific key, one to read one of its values, and the third one to close it. Well, the second one is the culprit. It's used for getting all kinds of values: string values, dword values and binary values. Only thing to get is a pointer to the value in the registry. So, we have to declare this function in different ways, one way for getting string values, one for getting dword values and one of coarse for getting binary values. Here are the declarations:

Function long RegOpenKeyExA    (ulong hKey, ref string lpSubKey, long lpReserved, long samDesired, ref ulong phkResult) library "advapi32.dll"
Function long RegCloseKey        (ulong hkey) library "advapi32.dll"
Function long RegQueryValueExA    (ulong hKey, ref string lpValueName, long lpReserved, ref long lpType, ref string lpData, ref long lpcbData) library "advapi32.dll"
Function long RegQueryValueNULL    (ulong hKey, ref string lpValueName, long lpReserved, ref long lpType, ref any lpData, ref long lpcbData) library "advapi32.dll" alias for "RegQueryValueExA"
Function long RegQueryValueString    (ulong hKey, ref string lpValueName, long lpReserved, ref long lpType, ref string lpData, ref long lpcbData) library "advapi32.dll" alias for "RegQueryValueExA"
Function long RegQueryValueLong    (ulong hKey, ref string lpValueName, long lpReserved, ref long lpType, ref long lpData, ref long lpcbData) library "advapi32.dll" alias for "RegQueryValueExA"
Function long RegQueryValueBinary    (ulong hKey, ref string lpValueName, long lpReserved, ref long lpType, ref char lpData[], ref long lpcbData) library "advapi32.dll" alias for "RegQueryValueExA"

As you can see, the RegQueryValueExA is declared in many ways. Now, how do we know what kind of type a value is? Well, we just have to call the function twice because all this information is provided by this function, only the first time, we have to catch the value of the pointer in an Any variable. Based on the provided information, we can call the function again, now with another declaration so that PowerBuilder knows what the value looks like. Check it out. Now, the difficult one is the binary one. These values are stored as paires of 2 bytes. What I did was mapping these values to an array of integers, which worked. Now, the values you see in the registry are hexadecimal but the values are returned as in base 10 (decimal), so if you want to have them in hex, you have to convert them yourself.

Check out the example PBL.

Hope you like it.

Back Up Next