Solved

RegSetValueEx

Posted on 1998-09-20
7
456 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now