Reading #REG_BINARY Registry entries?

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Reading #REG_BINARY Registry entries?

Post by PB »

At http://tinyurl.com/lkxz there is an example of how to read Registry
values of #REG_SZ and #REG_DWORD type, but not #REG_BINARY. :(
Does anyone know how to read #REG_BINARY values? Thanks.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Just like when you read a string value. (provide a buffer for the data and
it's size, and RegQueryValueEx_() will fill the buffer.

Example:

In the code you mentioned, line 70:
This call receives the type of data in 'lType' and it's size in 'cch'.
Now when 'lType' is #REG_BINARY, you need to allocate memory
of size 'cch'.

Now the actual call to get the value can look like this:

Code: Select all

lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, MemoryID(), @cch) 
Assuming you used AllocateMemory() to allocate the memory.

Here's a piece of code that fits in the Select/EndSelect of the
QueryValueEx() procedure in the code you mentioned:

Code: Select all

        ;For Binary
        Case #REG_BINARY
            If AllocateMemory(0, cch)
              lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, MemoryID(), @cch) 
              If lrc = #ERROR_NONE 
                ;
                ; Binary Data is now in the allocated buffer, do whatever you want with it.
                ;
              EndIf               
            Else
              ; allocation error
              lrc = -1
            EndIf
Timo
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks Freak, I got what I wanted by modifying your procedure like so:

Code: Select all

        Case #REG_BINARY 
            If AllocateMemory(0, cch) 
              lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType,  MemoryID(), @cch) 
              If lrc = #ERROR_NONE 
                ; 
                ; Binary Data is now in the allocated buffer, do whatever you want with it. 
               TStr1.s = ""
               TStr2.s = ""
               For i = 0 To cch-1
                  TStr1 = Hex(PeekB(MemoryID()+i))
                  If Len(TStr1) = 1 : TStr1 = "0" + TStr1 : EndIf
                  TStr2 +TStr1+" "
               Next
               Debug TStr2
                ; 
              EndIf                
            Else 
              ; allocation error 
              lrc = -1 
            EndIf
:D
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Maybe you also want to put a 'FreeMemory(0)' somewhere? :mrgreen:

Timo
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

LOL, yep -- forgot about that in all the excitement! :wink:
Wolf
Enthusiast
Enthusiast
Posts: 230
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Now how for write an #REG_BINARY value at registry ?

Not exist any help in forum or purearea sources.

I want set this value in reg at binary format: F6 B7 FF FF FF FF FF FF
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

Post by bingo »

@wolf

Code: Select all

DataSection 
regbin_data: 
Data.b 0,1,2,3,4,5,6,7,8,9,128,255 ;byte in decimal ! 
end_regbin_data: 
EndDataSection 

openkey = #HKEY_LOCAL_MACHINE 
subkey.s = "SOFTWARE" 
keyset.s = "test" 
hkey.l = 0 

RegCreateKey_(OpenKey,SubKey,@hKey) 
RegSetValueEx_(hKey,keyset,0,#REG_BINARY,?regbin_data,?end_regbin_data - ?regbin_data) 
RegCloseKey_(hKey) 
["1:0>1"]
Wolf
Enthusiast
Enthusiast
Posts: 230
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Very thanks bingo.

It's great :wink:
Post Reply