Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RegSetValueEx

Posted on 1998-09-20
7
Medium Priority
?
463 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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 100 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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