Solved

Using the Registry with MFC.

Posted on 1998-06-04
8
233 Views
Last Modified: 2013-11-19
I want to write my program's setup information into the registry.. for example, I want to add this to HKEY_CURRENT_USER

MyCompanyName\MyProgramsName\Version\<several keys with info>

what do I need to do to make the different directories and then the keys ??
0
Comment
Question by:VisualLR
8 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
Call CWinApp::SetRegistryKey(MyCompanyName) in the CWinApp::InitInstance.

CWinApp::SetRegistryKey
void SetRegistryKey( LPCTSTR lpszRegistryKey );

void SetRegistryKey( UINT nIDRegistryKey );

Parameters

lpszRegistryKey   Pointer to a string containing the name of the key.

nIDRegistryKey   ID/index of a key in the registry.

Remarks

Causes application settings to be stored in the registry instead of INI files. This function sets m_pszRegistryKey, which is then used by the GetProfileInt, GetProfileString, WriteProfileInt, and WriteProfileString member functions of CWinApp. If this function has been called, the list of most recently-used (MRU) files is also stored in the registry. The registry key is usually the name of a company. It is stored in a key of the following form: HKEY_CURRENT_USER\Software\<company name>\<application name>\<section name>\<value name>.

0
 

Author Comment

by:VisualLR
Comment Utility
I had already read that in the MSVC documentation. I turned to this site because it wasn't clear enough for me.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
So, which is not clear for you?
0
 

Author Comment

by:VisualLR
Comment Utility
well, how do I make the different directories?? if you could give me a short example it would be great. Cause Ive tried and I havent been able to do it... thanks.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:Andy_Keys
Comment Utility
I found that using the void SetRegistryKey(LPCTSTR szRegistryKey ); too limiting, Look at using the std
RegCreateKeyEx fn. By passing a path with \ int the string for the 2nd parameter you can use it like a directory. ie. if you pass in <zzzz>\<xxx> you create key <zzzz> and it has a child/sub key of (xxxx). Once this key is created you can the
RegSetValueEx fn to set data values.  If you want some examples reply let me know


0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
Comment Utility
BOOL CMyApp::InitInstance()
{
    ...
    this->SetRegistryKey(_T("MyCompanyName"));
    ...
}


CWinApp *pApp = ::AfxGetApp();
pApp->WriteProfileString(_T("Version"), _T("Author"), _T("VisualLR"));

This will create the subkey "Version" and its value name is "Author" and its value data is "VisualLR".

Run Registry Editor to see it.
0
 

Expert Comment

by:mmachie
Comment Utility
checkout www.codeguru.com  there is a registry class you can use that wraps the api calls.
0
 

Author Comment

by:VisualLR
Comment Utility
Thanks! With you example I was able to make it. Thanks a lot.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now