Registry

Windows specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Hey Mr.Skunk, maybe you can help me with this one...
How would I convert this into PureBasic so I can query a registry entry?

LONG RegQueryValueEx(
HKEY hKey, // handle to key
LPCTSTR lpValueName, // value name
LPDWORD lpReserved, // reserved
LPDWORD lpType, // type buffer
LPBYTE lpData, // data buffer
LPDWORD lpcbData // size of data buffer
);
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

The Constant listed for HKEY_LOCAL_MACHINE is (HKEY)0x80000002 and I would like to read a value out of the SOFTWARE folder.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

OK, this is what I've got so far...

#HKEY_LOCAL_MACHINE=2147483650
ok.l=RegQueryValue_(#HKEY_LOCAL_MACHINE,"SOFTWARE\COMPANY\APP\User",*buffer, *len)
result$=peekS(*buffer)
MessageBox_(0, str(ok)+" / "+result$, "Result", 0)
End

I must be getting close cause the error that is now returned says:
ERROR_FILE_NOT_FOUND
(Note: I went with RegQueryValue since RegQueryValueEx returns a syntax error)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Hello, as i've not the key you mentionned in your precedent article, this example will read the current version string of Zone Alarm (firewall)

; Little example to read Registry values



#PB_Window_ThickFrame=262144
InitWindow(0)
If OpenWindow(0, 100,100, 600,240, #PB_Window_ThickFrame | #PB_Window_SystemMenu ,"Registry example")

;
; Open the Key
;

subkey.s="Software\Zone Labs\ZoneAlarm" ; Key path (without the keyname you want to read)
keyhandle.l=0 ; the handle of the key, return by the RegOpenKeyEx function
a.l=RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,@subkey,0,#KEY_READ,@keyhandle) ; to open the key

;
; Read the KEy
;

name$="CurrentVersion" ; name of the key you want to use
type.l=0 ; type of the key, returned by the function
data$=" " ; buffer where you will read result (maxlength = 255)
datasize.l=255 ; max Length of the result buffer

a.l=RegQueryValueEx_(keyhandle,@name$,0,@type,@data$,@datasize) ; read the key

;
; Close the Key
;

a.l=RegCloseKey_(keyhandle) ; free the momory of the key handle

drawingoutput(windowid())

If type=#REG_SZ ; if key type=text
a$=left(data$,datasize-1) ; get the result string (without the final '0')
locate(20,20):drawtext(a$)
EndIf

stopdrawing()

Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventCloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
End

Hope it helps, feel free to ask if it's not clear.


Mr Skunk


Edited by - mr.skunk on 26 June 2001 14:20:43
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Okay... So I was off by quite a ways :(

Now where did the @ come from??
And why are some constants like HKEY.. already predefined and otheres are not?

Geez, now I'm confused.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

@data$ for example is used to pass, not the string data$, but the pointer to that string (address where the string is).
If some constant are not definied, means that Fred has not include them to his constants definitions in PB.
I think you can send him these constants to be included in the future release of PB.


Mr Skunk
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Thanks Mr. Skunk
Another question for you...

How do you know when to use @ or when to use * ???
I thought * was used for pointers.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

@ is a pointer for any sting/numerical variable within PB.
* is only when YOU define a pointer

example :
Structure array
...
EndStructure

*Myarray.array (this is pointer that you define to access directely your structure. But when you want to access a variable address you don't create with '*', always use "@")


Mr Skunk
Post Reply