CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2003
    Posts
    815

    CRegKey::SetValue

    Hello,

    I'm tring to use the MFC CRegKey
    I get a warining about the SetValue with the 2 parameters that is is depricated, so I guess I have to use the setValue with the 4 parameters

    I have 3 question about the SetValue with the 4 parameters
    1. how do I set a DWORD?
    2. Do I need to use open first?
    3. Can anyone show me an example for the use of SetValue with 4 parameters?

    thanks
    avi

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788
    see this FAQ for a startup and adapt it to your needs.

  3. #3
    Join Date
    Sep 2003
    Posts
    815
    I have looked at this FAQ before posting this thread
    I have used this sample, but I get a compliation error about SetValue is being deprecated

    here is the warning:

    d:\Projects\Registry\Registry.cpp(170): warning C4996: 'ATL::CRegKey::SetValue' was declared deprecated

    I saw that there are a few SetValue fucctions and only the one with the 4 parameters is not deprecated, but I don't know how to use it (specally for DWORD)

    thanks again
    avi

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234
    Instead of CRegKey::SetValue deprecated functions, use
    CRegKey::SetDWORDValue or
    CRegKey::SetStringValue or
    CRegKey::SetMultiStringValue.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Sep 2003
    Posts
    815
    thanks

    that's exactly what I needed.

    avi

  6. #6
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    Re: CRegKey::SetValue

    Sorry to revive an old thread. I inherited old code that needs updating into VS2010 and I'm not very familiar with C++. At all. So I apologize for asking painfully obvious questions. :-)

    Here's what I have
    Code:
     key.SetValue(HKEY_LOCAL_MACHINE, "Software\\afolder\\somefolder",DataPath,"DataPath");
    where CString DataPath = "D:\\"

    I see that I'm supposed to use "SetDWORDValue" or something similar, but I'm not seeing a solution which explicitly stores data to the specified HKEY. Do I need to set it up somewhere else? Is it not necessary?
    There are a ton of these 'superseded' commands to update, I'm not completely sure how to translate them into the new commands.

    Thanks for your help! I really appreciate it.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CRegKey::SetValue

    Just look for the appropriate overloaded CRegKey method in msdn.

    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx

    In the case above, you aren't going to use the SetDWORDValue method since you aren't setting a DWORD value (i.e. "D:\\" isn't a DWORD).

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: CRegKey::SetValue

    Quote Originally Posted by Grue42 View Post
    Here's what I have
    Code:
     key.SetValue(HKEY_LOCAL_MACHINE, "Software\\afolder\\somefolder",DataPath,"DataPath");
    where CString DataPath = "D:\\"
    You should be very careful with writing to HKEY_LOCAL_MACHINE. It is not allowed for users withot Admin rights.
    Victor Nijegorodov

  9. #9
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    Re: CRegKey::SetValue

    Thank you for the advice VictorN - this software comes pre-installed on computers so the users are setup with admin rights. It's a necessary evil.

    I can about put a button on a panel and make it do a simple task. I'm *very* new to this. The idea was that updating this existing software would be a good way to learn...

    Thank you Arjay. I found this previously: http://technet.microsoft.com/en-us/s.../xka57xy4.aspx and tried to match what SetValue did - but didn't find anything with matching parameters including the hKeyParent except maybe CSettingsStore if I can/should use it in conjunction with something else?
    I feel a bit stupid for not being able to extrapolate this to a new command, but I seem to just be going in circles. Can anyone help with a specific example?

    Maybe I should have specified that
    CRegKey key;

    Again, thank you all for your patient help and advice!

  10. #10
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: CRegKey::SetValue

    Perhaps, something like (just a pseudo code!)
    Code:
    CRegKey key(HKEY_LOCAL_MACHINE);
    key.SetKeyValue(_T("Software\\afolder\\somefolder"), DataPath, _T("DataPath"));
    Victor Nijegorodov

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CRegKey::SetValue

    Quote Originally Posted by VictorN View Post
    Perhaps, something like (just a pseudo code!)
    Code:
    CRegKey key(HKEY_LOCAL_MACHINE);
    key.SetKeyValue(_T("Software\\afolder\\somefolder"), DataPath, _T("DataPath"));
    Exactly

  12. #12
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    Re: CRegKey::SetValue

    That did it - perfect. I didn't realize I could specify the CRegKey like that.
    Thank you all very much! I really appreciate the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured