Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need an example for the GetRegKey() in registry.vcx
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00572563
Message ID:
00572722
Vues:
123
>>Snip
>>
>>You need to first open the key using the OpenKey() method. If you do not specify a key it defaults to HKEY_CLASSES_ROOT. Here's an example:
lckey = "Excel.Application\CurVer"
>>SET CLASSLIB TO REGISTRY.VCX ADDITIVE
>>oReg = CREATEOBJECT("Registry")
>>RELEASE CLASSLIB REGISTRY
>>IF oReg.OpenKey(lckey) = 0 && No error
>>  lcvalue = ""
>>  IF oReg.GetKeyValue("", @lcvalue) = 0 && No error
>>    ? lcvalue
>>  ENDIF
>>  oReg.CloseKey()
>>ENDIF
>
>George,
>
>It works fine, but if I purely as an example do the following:
>
>lckey = "Environment\Temp"                && That's ok, right?
>HKEY_CURRENT_USER=-2147483647             && Nothing wrong with that?
>? oReg.OpenKey(lckey,HKEY_CURRENT_USER)=0 && Returns .F.
>
>
>oReg.OpenKey(lckey,HKEY_CURRENT_USER,.F.)=0 didn't do any better.
>
>IntelliSense prompts for CLOOKUPKEY which I assume equals lcKey,
>NREGKEY, which I figured as HKEY_CURRENT_USER and finally lcreatekey, which I set as .F.
>
>Please bear with me, because I obviously have not understood all of this just yet.

No problem. Glad to help.

Everything in the above looks OK and I'll give you some explanations at the end of this. The first question that I'd pose to you here is, "Do you know for certain that the key exists?" If it does not, then it will return non-zero, unless you tell it to create the key. The second question, provided that you know that the key exists is, "What is the return value?" That will help establish what the problem is.

When you call OpenKey() passing only the two parameters as in the first instance, you tell the routine not to create the key of it doesn't exist. Even by passing .F. as in the second example above, you're telling it the same thing. However, if you pass .T. to it, it will create the key for you if it doesn't exist.

The handle to the open registry key is stored in the nCurrentKey property.

If the problem is that the key might not exist, then I'd suggest call the IsKey() function before trying to open the key. Then you'll know how to proceed from there.

Whenever I'm confronted with code that I didn't write such as legacy code or, as in this case, code from an outside source, I tend to sit down and re-write it so that it conforms to my current coding standards. This helps give me insight into what the code does and how it does it. In the case of the registry class that ships with VFP, this is exactly what I've done, and am doing now with the _crypt.vcx class library. If after doing that, I still don't think I've a good grip on what's going on, I'll step through the code.

hth,
George

Ubi caritas et amor, deus ibi est
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform