Solved

RegSetValueEx

Posted on 1998-09-20
7
462 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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 …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

627 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