GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Mar-2004, 03:36
janestockdill janestockdill is offline
New Member
 
Join Date: Mar 2004
Posts: 1
janestockdill is on a distinguished road

How to read REG_DWORD values from registry


Hello,

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  
Old 03-Mar-2004, 08:04
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
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:
int value;

value = atoi( RegQueryValueEx(...) );

If you want a long int, use the function atol.

HTH
  #3  
Old 03-Mar-2004, 13:49
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Maybe my next tutorial should be on registry programming in C/C++... that would be a great learning experience for me
  #4  
Old 03-Mar-2004, 17:18
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by aaroncohn
Maybe my next tutorial should be on registry programming in C/C++... that would be a great learning experience for me
No way.

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:
I am new to C / C++ programming and am having a problem trying to read REG_DWORD values from the registry

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  
Old 04-Mar-2004, 12:27
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
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  
Old 04-Mar-2004, 13:16
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by aaroncohn
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.
As am I, but in a program, a slight mistake in coding can have huge consequences. Also, there are those on the forum that don't even know what a char is. You wanna let them write to the registry?

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  
Old 04-Mar-2004, 13:37
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by aaroncohn
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.

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  
Old 04-Mar-2004, 15:53
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
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  
Old 04-Mar-2004, 18:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by aaroncohn
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.
For this I use "Registry First Aid". Let them take care of it.

My 2 dracmas
 
 

Recent GIDBlogConfiguring iptables for Webmin Servers Index Module by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 10:52.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.