Solved

RegSetValueEx

Posted on 1998-09-20
7
461 Views
Last Modified: 2013-12-03
I have created a key "Fire" using RegCreateKeyEx.
This "Fire" key is supposed to have several data fields.

How do i create DWORD data fields for this "Fire" and write integers to them?
Below is my code trying to write an integer 5 to a "Datafield1" with no success.
Thanx.

HKEY KeyOpened;
DWORD Disp ;

if (RegCreateKeyEx( HKEY_CURRENT_USER,
   "Software\\MYCompany\\MYModule\\Fire",
   0,
   NULL,
   REG_OPTION_NON_VOLATILE,
   KEY_ALL_ACCESS,
   NULL,
   &KeyOpened,
   &Disp)  == ERROR_SUCCESS)
{
   RegSetValueEx( KeyOpened,
       "DataField1",
       0,
       REG_DWORD,
       (BYTE*)5,
       sizeof(DWORD) ;

   RegCloseKey(KeyOpened);
}
0
Comment
Question by:nancytan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Author Comment

by:nancytan
ID: 1414601
Edited text of question
0
 

Author Comment

by:nancytan
ID: 1414602
Edited text of question
0
 

Author Comment

by:nancytan
ID: 1414603
Edited text of question
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:nancytan
ID: 1414604
Edited text of question
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1414605
Try without casting the 5, just pass it as it is, or store it in a DWORD first, and pass a reference to it
DWORD dw=5
RegSetValueEx(..., &dw)
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1414606
DWORD NewValue = 5

RegSetValueEx( KeyOpened,
          "DataField1",
          0,
          REG_DWORD,
          (BYTE*) &NewValue,
          sizeof(DWORD) ;
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414607
If this is C++ (not c), you should also be able to do

RegSetValueEx( KeyOpened,
          "DataField1",
          0,
          REG_DWORD,
          (BYTE*) &DWORD(5),
          sizeof(DWORD) ;

the other way is a little cleaner and easier to understand, however, this way doesn't require you to define an extra DWORD variable.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question