Registry programming literacy (2)

xiaoxiao2021-03-06  45

two. RegopenKeyex, and RegCloseKey

Let's talk about regopenkeyex, you know that it means to open a key, because RegreateKeyex can open a key, so this function is a bit. However, this function is simpler n times higher than RegcreateKeyex, so it is still very useful. It declares this:

Long Regopenkey (HKEY HKEY, LPCTSTSTR LPSUBKEY, PHKEY PHKRESULT);

At first, are these parameters very familiar? HKEY, LPSUBKEY, PhkResult The meaning of these parameters is nothingord of these parameters in the RegcreateKeyex function. Not much here, I will know it in the last season. The return value is still an oldest, and Error_Success means that it was successful.

Let's take a look at RegCloseKey, it is very simple, there is only one parameter:

Long regcloseKey (HKEY HKEY) is closed, after turning off a button, the handle is useless. I don't know if it is closed and there is no difference, but it is always good to develop habits that are closed at any time. return value? Needless to say, homingly.

three. RegSetValueex

RegsetValueex, that is, a key handle is already known, and the data of this key is new or rewritten. Just as you already know a folder, then change the files. I know it is useful. For some systematic data changes, you can produce a very cattle effect! ! ! Ah, it's really exciting! ! ! But don't change, don't look for me if you are broken. Less nonsense, look at how to use:

Long RegSetValueex (

HKEY HKEY,

LPCTSTR LPSUBKEY,

DWORD reserved,

DWORD DWTYPE,

LPCTSTR LPDATA,

DWORD CBDATA

);

HKEY: Don't you say it?

LPSUBKEY: String, is the name of the data item you want to set, just like the file name.

RESERVED: Users must be 0.

DWTYPE: The type of data, there are many kinds, I only say two commonly used. REG_SZ and REG_DWORD are string and DWORD (unsigned long). It is generally these two.

LPDATA: It is the data you want to set. If it is a string, you must force the first address to convert the first address into a symbolic pointer, and then pass. If it is an integer, first take the address, then force to convert into a symbolic character pointer, and then the past.

DWORD CBDATA: The length of the data you want to set, if it is a string type, Strlen 1. If it is an integer, it is 4. The return value is the same.

Still give an example:

#include

void main ()

{

DWORD DWRES;

HKEY HK;

Char szname [4] = "I";

DWORD DWSCORE = 100;

RegcreateKeyex (HKEY_LOCAL_MACHINE,

"Software // Carrier Studio // Hello",

0,

NULL,

REG_OPTION_NON_VOLATILE,

Key_all_access,

NULL,

& hk,

& dwres

);

RegSetValueex (HK, "Name", 0, Reg_SZ, (LPBYTE) SZNAME, 3);

RegSetValueex (HK, "Score", 0, Reg_dword, (LPBYTE) DWSCORE, 4);

RegcloseKey (HK);

}

Ok, I wrote so much, I was tired, I took a break.

转载请注明原文地址:https://www.9cbs.com/read-110268.html

New Post(0)