Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need an example for the GetRegKey() in registry.vcx
Message
De
24/10/2001 09:51:30
 
 
À
24/10/2001 09:35:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00572563
Message ID:
00572572
Vues:
48
Peter,
I'm using the following GetRegKey() function. It may give you some ideas.
************************************************
PROCEDURE GetRegKey
************************************************
LPARAMETERS tcOptName, tcKeyPath, tcUserKey

#INCLUDE "ffc\registry.h"

* Example:
* GetRegKey("DefaultDSNDir", "Software\Odbc\Odbc.ini\Odbc File Dsn", "HKEY_LOCAL_MACHINE")		
* Returns: "C:\Program Files\Common Files\ODBC\Data Sources\"

*-- check parameters
ASSERT TYPE("tcOptName") = "C" AND NOT EMPTY(tcOptName) MESSAGE "GetRegKey() requires parameter <tcOptName> as 1st parameter!"
ASSERT TYPE("tcKeyPath") = "C" AND NOT EMPTY(tcKeyPath) MESSAGE "GetRegKey() requires parameter <tcKeyPath> as 2nd parameter!"
ASSERT TYPE("tcUserKey") = "C" AND NOT EMPTY(tcUserKey) MESSAGE "GetRegKey() requires parameter <tcUserKey> as 3rd parameter!"

tcUserKey = UPPER(ALLTRIM(tcUserKey))

LOCAL lnUserKey

DO CASE
	CASE tcUserKey = "HKEY_CLASSES_ROOT"
		lnUserKey = HKEY_CLASSES_ROOT
	CASE tcUserKey = "HKEY_CURRENT_USER"
		lnUserKey = HKEY_CURRENT_USER
	CASE tcUserKey = "HKEY_LOCAL_MACHINE"
		lnUserKey = HKEY_LOCAL_MACHINE
	CASE tcUserKey = "HKEY_USERS"
		lnUserKey = HKEY_USERS
	OTHERWISE
		??CHR(7)
		WAIT WINDOW NOWAIT "'" + tcUserKey + "' is not a valid registry root!"
		RETURN ""
ENDCASE

LOCAL loReg, lcOptValue, lnErrNum

loReg       = NEWOBJECT("Registry", HOME() + "ffc\registry")
lcOptValue  = ""
lnErrNum    = loReg.GetRegKey(tcOptName, @lcOptValue, tcKeyPath, lnUserKey)

RELEASE loReg

IF lnErrNum <> 0
	??CHR(7)
	WAIT WINDOW NOWAIT "Could not find Key"
	RETURN ""
ELSE
	*-- return value
	RETURN lcOptValue
ENDIF

*-- EOF GetRegKey ---------------------------------------------------------------------------------
HTH

>I have been trying to get the registry functions to work to no avail.
>
>I admit to being a bit dense sometimes, but after carefully reading throug the functions and the sample code it's still all greek to me.
>
>The following is part of the code for the GetKeyValue() function:
>
>
>LPARAMETER cValueName,cKeyValue
>
>LOCAL lpdwReserved,lpdwType,lpbData,lpcbData,nErrCode
>STORE 0 TO lpdwReserved,lpdwType
>STORE SPACE(256) TO lpbData
>STORE LEN(m.lpbData) TO m.lpcbData
>
>DO CASE
>CASE TYPE("THIS.nCurrentKey")#'N' OR THIS.nCurrentKey = 0
>	RETURN ERROR_BADKEY
>
>And that's as far as it ever gets.
>
>The nCurrentKey is initially 0 and I dont see it being set anywhere, and it's not part of the parameters, so how does this work and what's the value supposed to be?
>
>We used to have lots of (not always very good) code samples in VFP Help butn it seems like a lot of that went down the drain with VFP7.
>
>Anyway,
>
>TIA
Daniel
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform