Programming using C to register the table API

Source: Internet
Author: User

Registry This is a fun thing to do, but it's always a hassle to find what you need in a layer-by-layer containment relationship, and who remembers the path?

Anyway, I will not remember, write a small program, let the path saved into the code inside. Release your brain's storage capacity.

The individual demonstrates simple programming of the Registry API as an example of an aero effect that opens Windows 8.

Process

First, familiarize yourself with the simple process:

You can start with a simple understanding.

Code

Here are two functions, the code of the two functions is almost the same, only the modified value is not the same, so I will just a simple overview of a function.

parameters

This function includes three parameters, all of which are individual presets, from here :

Note: Here is a reminder that the path to use two "\", do not forget the escape character.

Error Judgment

It is necessary to open or set an item to determine whether it is successful or not. If the success will return 0, you can also use ERROR_SUCCESS.

Using functions

Open an item with RegOpenKeyEx (), here is the function prototype (from MSDN):

The first parameter is the system preset, hkey type, note that this is not a kernel type. All default values are listed here:

The second parameter is a sub-path.

The third parameter of MSDN gives must be 0.

The fourth parameter sets the permissions to be manipulated, writable or read-only, and so on.

The fifth pointer is the output, and here it is necessary to define a variable of type hkey before giving the pointer.

Set the value of an item with RegSetValueEx (), here is the function prototype (from MSDN):

The first parameter is an existing or open item, and here is the last parameter after opening the item with RegOpenKeyEx ().

The second parameter is the name of the item to which you want to set the value, knowing that the key name can use this function.

The third parameter, MSDN, must also be 0.

The fourth parameter is the default open mode, where the REG_DWORD is a 32-bit number.

The fifth parameter is the byte type of the value to be set, and the integer value of Valueofaero is converted to byte type with the coercion type.

The sixth parameter is the length of the set value, and the length of the Valueofaero can be obtained directly with sizeof ().

Here to the last step, close the open item, directly with RegCloseKey (), the argument is an open item.

Finally logout the system (actually close the "desktop Window Manager" on it, but I don't know how to do it) can open the Aero effect. The effect of this opening is not perfect, but the purpose of registry programming has been achieved.

Extended

Because two function code, this can write more than one function, implement the same part of the code, implement code reuse, and simplify some code, this is also easy to implement, I do not explain.

Also, you can add the error function in the code, GetLastError () can be easily implemented, of course, you can also convert the error code to text errors.

At last

Finally, the specific parameters of the two function links (more operation functions can be found in MSDN, is a good place):

RegOpenKeyEx ():

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724897 (v=vs.85). aspx

RegSetValueEx ():

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724923 (v=vs.85). aspx

Programming using C to register the table API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.