How to set/read registry key in C

Registry keys are used to store various values used by programs you use.

Setting or getting the values of registry keys is really easy.

First, you need to open the registry key:

To write a value to a registry key you need to use:

The RegSetValueEx function is used to set a value in the registry. Its parameters are: the variable holding the opened registry key, the name of the key value you want to set, the type of the key value you want to set (REG_SZ is for string values, REG_DWORD is for integer values), the data to be stored for that value and the size of the data.

To read from a registry key you have to use:

The function used for retrieving registry values is RegQueryValueEx. You need to specify as parameters the variable holding the opened registry key, the name of the values to be read, the type of the value, a variable to hold the result and the size of the result.

And that’s it!

Don’t forget to close the registry key at the end:

52 weeks of code

I haven’t finished the haskell challenge from 52wok yet, but I’ve almost finished reading the tutorial and decided what program to write after reading the tutorial. I will try to solve one or two more problems from Project Euler. I have solved a few some time ago, but in java.

This week’s challenge is C++. I’ve already submitted something, a small gui for converting between meters and feet using the win32api. I haven’t worked with win32api much, so this was a good exercise for me.