![]() |
|
#1
|
|||
|
|||
How to read REG_DWORD values from registryHello,
I am new to C / C++ programming and am having a problem trying to read REG_DWORD values from the registry. When my registry value is of type REG_SZ I have no problem because the type it puts the value is of the same type. When I want to read a REG_DWORD however it the RegQueryValueEx method still wants to put the return value into an unsigned char* and I want to put it into a DWORD. When I use a simple cast from DWORD to unsigned char* this doesn't work. How can I get the value from the registry correctly and end up with the value in a DWORD variable (ideally I need it as an int if this makes a difference) Thanks in advance Jane |
|||
|
#2
|
||||
|
||||
|
Hello Jane. Welcome to GIDForums
[disclaimer]I am not familiar with Registry programming or even Windows programming for that matter. If what I tell you seems inconsistent please disregard[/disclaimer] Okay, it appears that RegQueryValueEx wants to return a char* so that it can return any type of value. You can do a cast from a char* to an int but the result will not be what you want. What you need to use is an auxillary function to convert this into an int. The function atoi does exactly this. CPP / C++ / C Code:
If you want a long int, use the function atol. HTH |
|
#3
|
||||
|
||||
|
Maybe my next tutorial should be on registry programming in C/C++... that would be a great learning experience for me
|
|
#4
|
||||
|
||||
|
Quote:
The last thing I feel we want to give people is a loaded gun with a hair trigger -- just because they ask for it. IMHO, the fact that the OP states Quote:
raises a big red flag! "I'm new to surgery. I wanna see if I can do neurosurgery on you." Learn to code without getting into an area to kill your system. Playing around with the registry is dangerous. It can give your computer cancer (or worse) if you do something wrong and can't back out of it. If you're going to continue playing around with the registry, what are your plans correcting problems if you screw it up? If you are going to continue, I recommend you install a program like GoBack so that when you f'up your system, you can restore it to it's original state. My 2 cents |
|
#5
|
||||
|
||||
|
Well, I don't know about other people, but I'm perfectly competent to make changes in my registry without causing problems, and have done so on numerous occasions.
|
|
#6
|
||||
|
||||
|
Quote:
Learn to code normal programs and get competent without dealing with the registry. Then learn enough about the OS internals (specifically how and why the registry works) before getting into system changes. My 2 bits... |
|
#7
|
||||
|
||||
|
Quote:
Well, I don't feel that I or anyone else for that matter should mess with the registry. My opinion is that it is overly complicated and too easy to f' up. In my company if I ever caught someone messing with the registry on a company machine, it would not go well for them. That being said, I am not going to tell other people what to do or not to do. If people come here with a question, I will answer it to the best of my ability. It may not be good advice (hell, it may not even be correct), but they can do with it what they will. My 2 cents. |
|
#8
|
||||
|
||||
|
I really wouldn't reccommend editing the registry to anyone who doesn't need to do it. I usually only go into my registry to clean out bad program references (sometimes uninstallers forget to get rid of registry entries) and to get a CD-key that I lost a hard-copy of.
My 2 pesos. |
|
#9
|
||||
|
||||
|
Quote:
My 2 dracmas |
Recent GIDBlog
Configuring iptables for Webmin Servers Index Module by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| store values | skyloon | MySQL / PHP Forum | 6 | 23-Jul-2005 03:29 |
| Scripts not being read... | amneziac85 | Apache Web Server Forum | 2 | 26-Jan-2004 05:42 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The