C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 11th, 2006, 06:24 AM
Cyberfreak Cyberfreak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 8 Cyberfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 56 sec
Reputation Power: 0
Question How to create a DWORD using C++?

I've tried many different ways to write a program that ones opened, it will create a DWORD file in a registry folder and set the DWORD's value to 1- but I seem to be missing something because the complier won't let me compile it.

Can someone please write an example of a program like that so that I can see what I missed in some of the programs that I tried to write.
Thanks.

Reply With Quote
  #2  
Old September 11th, 2006, 06:42 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 9
Sorry, I can't help; I have no idea.

Costas

Reply With Quote
  #3  
Old September 11th, 2006, 07:04 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,030 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 1 Week 12 h 39 m 41 sec
Reputation Power: 12
Send a message via ICQ to Itsacon
afaik, the best way is still to create a .reg file, and call regedit with that file using the system() call from C.

Search google to see how modifying the registry by means of .reg files works.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 592

Reply With Quote
  #4  
Old September 11th, 2006, 09:50 AM
Cyberfreak Cyberfreak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 8 Cyberfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by Itsacon
afaik, the best way is still to create a .reg file, and call regedit with that file using the system() call from C.

Search google to see how modifying the registry by means of .reg files works.


Why didn't I think of that. Thats a great idea, thanks.

Reply With Quote
  #5  
Old September 11th, 2006, 10:26 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,030 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 1 Week 12 h 39 m 41 sec
Reputation Power: 12
Send a message via ICQ to Itsacon
You're welcome. Good luck :-)

Reply With Quote
  #6  
Old September 11th, 2006, 06:53 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 10
Send a message via AIM to ubergeek
C Code:
Original - C Code
  1.  
  2. #include <windows.h>
  3.  
  4. int main()
  5. {
  6.     HKEY hHKCU = NULL, hMyKey = NULL;
  7.     DWORD value = 1;
  8.     if (RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_WRITE, &hHKCU) == ERROR_SUCCESS)
  9.     {
  10.         if (RegCreateKeyEx(hHKCU, "My_Subkey\\MyKey", 0, NULL, 0, KEY_WRITE, NULL, &hMyKey, NULL) == ERROR_SUCCESS)
  11.         {
  12.             RegSetValueEx(hMyKey, "ThisIsADword", 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
  13.             RegCloseKey(hMyKey);
  14.         }
  15.  
  16.     }
  17.  
  18.     return 0;
  19. }

Creates a key under HKCU\My_Subkey\MyKey\ThisIsADword with type REG_DWORD and value 1. I'm on WinXP SP2 using Dev-C++.

Reply With Quote
  #7  
Old September 12th, 2006, 08:05 AM
Cyberfreak Cyberfreak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 8 Cyberfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by ubergeek
C Code:
Original - C Code
  1.  
  2. #include <windows.h>
  3.  
  4. int main()
  5. {
  6.     HKEY hHKCU = NULL, hMyKey = NULL;
  7.     DWORD value = 1;
  8.     if (RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_WRITE, &hHKCU) == ERROR_SUCCESS)
  9.     {
  10.         if (RegCreateKeyEx(hHKCU, "My_Subkey\\MyKey", 0, NULL, 0, KEY_WRITE, NULL, &hMyKey, NULL) == ERROR_SUCCESS)
  11.         {
  12.             RegSetValueEx(hMyKey, "ThisIsADword", 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
  13.             RegCloseKey(hMyKey);
  14.         }
  15.  
  16.     }
  17.  
  18.     return 0;
  19. }

Creates a key under HKCU\My_Subkey\MyKey\ThisIsADword with type REG_DWORD and value 1. I'm on WinXP SP2 using Dev-C++.


Thanks.

Reply With Quote
  #8  
Old September 14th, 2006, 08:34 AM
Cyberfreak Cyberfreak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 8 Cyberfreak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 56 sec
Reputation Power: 0
One more question.
If I wanted to write a program that creates a REG_SZ file, so I would write REG_SZ = This is a reg file (for example) instead of DWORD value = 1 and change REG_DWORD to REG_SZ and the sizeof(DWORD) to sizeof(REG_SZ)?
Thanks.

Reply With Quote
  #9  
Old September 14th, 2006, 06:17 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 10
Send a message via AIM to ubergeek
I haven't tried it, but to change to REG_SZ I would first try these steps:
-change DWORD value = 1; to probably LPCSTR value = "This is a registry key.";
-change REG_DWORD to REG_SZ in the RegSetValueEx function call
-the last parameter to RegSetValueEx is the length of the data, so change it to the actual length of the string, i.e. strlen(value) (or count the chars in value beforehand and add 1 for the null terminator)
-change the (BYTE*)&value to just (BYTE*)value since an LPCSTR is already a pointer (to some form of char)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > How to create a DWORD using C++?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap