Solved

RegSetValueEx

Posted on 1998-09-20
7
459 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 Scheduled Tasks 11 88
Slow process to read Excel 15 124
What is MicroStrategy.NET? 2 68
What the difference between blend and Visual Studio 3 99
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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