Registry Problem

This is a discussion on Registry Problem within the Windows Programming forums, part of the Platform Specific Boards category; I'm using the WIN32 API, not the MFC but I've got a problem my program has a settings dialog and ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    23

    Unhappy Registry Problem

    I'm using the WIN32 API, not the MFC but I've got a problem my program has a settings dialog and i need to keep a integar saved for the next time the program is used. I'm going to use the Registry to do this but I create a key set it's value then request the value and ouput the value but instead of the original value being output i get a number Around 150,000 instead. Heres my code:

    Code:
    int value = 1234;
    HKEY hk;
    int outputvalue;
    char bufferedvalue[100];
    DWORD dwDisposition,buffersize;
    buffersize = 4;
    RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\EventLog\\program\\Settings",
    0,NULL,0,KEY_ALL_ACCESS,NULL,&hk,&dwDisposition);
    RegSetValueEx(hk,TEXT("num"),0,REG_DWORD,(LPBYTE)value,sizeof(value));
    RegQueryValueEx(hk,TEXT("num"),NULL,NULL,outputvalue,&buffersize);
    sprintf(bufferedvalue,"The value is: %d",outputvalue);
    MessageBox(NULL,bufferedvalue,"Result",MB_OK);
    cal

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    RegSetValueEx(hk,TEXT("num"),0,REG_DWORD,(LPBYTE) &value,sizeof(value));
    RegQueryValueEx(hk,TEXT("num"),NULL,NULL,&outputvalue,&buffersize);
    Also, I seriously doubt that you want to store data at the place you are. Configuration data common to all users is typically stored at:
    Code:
    "HKLM\Software\Your Company\Your Program\"
    while data specific to each user is stored under HKCU:
    Code:
    "HKCU\Software\Your Company\Your Program\"
    Even for services.
    Last edited by anonytmouse; 10-21-2004 at 10:20 AM.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    23
    I figured out how to fix the problem myself (set the sixth param of RegSetValue() to sizeof(DWORD)) but thanx for the Registry Path tip.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Possible Windows MDAC problem
    By BobS0327 in forum Tech Board
    Replies: 3
    Last Post: 06-28-2006, 04:57 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21