getting a DWORD registry value

This is a discussion on getting a DWORD registry value within the Windows Programming forums, part of the Platform Specific Boards category; Ok, so i can get the registry to give me a string, but i have a problem with getting a ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    getting a DWORD registry value

    Ok, so i can get the registry to give me a string, but i have a problem with getting a dword value. Here is an example of what i am trying to do:

    Code:
    DWORD reg_value, dw;
    
    if (RegQueryValueEx (Key, "SettingA", NULL, NULL, (LPBYTE) reg_value, &dw) != ERROR_SUCCESS)
    	Alert("You have a problem!");
    However, even though i have the registry value "SettingA" set as 0x10 (16 dec) reg_value always turns out 0. Anyone know whats wrong?
    HA! I WIN!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Use the fourth parameter to see what type it actually is being stored as. Granted, "float" is not an option. If you put 0x10 into a float using a memcpy-type operation (which you did here), you will get a value of 2.2420775429197073e-44 back, which will probably print as 0 unless you print it with %e or %g.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    reg_value is declared as a DWORD, not a float. I want to get 16dec into the variable reg_value which should work. Actually in my program I did use the fourth parameter and I am getting the correct type, the variable is simply not loading right. Can anyone provide a short example of how this is supposed to be done?
    HA! I WIN!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Wow. Don't ask me where I got float from, 'cause it's just not there. Anyway, the fifth parameter needs to be a pointer to the data.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    I think im still missing something... is it right to cast reg_value to LPBYTE to pass it in, or does reg_value need to be a pointer? I just can't understand why this is goin on...
    HA! I WIN!

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    i got it... i didnt realize that i needed to pass it as "(LPBYTE) &reg_value" and not "(LPBYTE) reg_value". Thanks!
    HA! I WIN!

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Not that confusing -- you got it right the second time:
    Code:
    if (RegQueryValueEx (Key, "SettingA", NULL, NULL, (LPBYTE) &reg_value, &dw) != ERROR_SUCCESS)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  3. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 01:15 PM
  4. [C] error while writting in the registry (DWORD)
    By BianConiglio in forum Windows Programming
    Replies: 2
    Last Post: 09-19-2004, 06:34 PM
  5. storage size of regs is unkown
    By Vertex34 in forum C Programming
    Replies: 5
    Last Post: 11-04-2003, 10:17 AM

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