Solved

Using the Registry with MFC.

Posted on 1998-06-04
8
235 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
ID: 1316037
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
ID: 1316038
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
ID: 1316039
So, which is not clear for you?
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Author Comment

by:VisualLR
ID: 1316040
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
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1316041
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
ID: 1316042
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
ID: 1316043
checkout www.codeguru.com  there is a registry class you can use that wraps the api calls.
0
 

Author Comment

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 93
Generic progress indicator 6 117
ORA-01403: no data found 43 101
JQuery serialize and unserialize 8 87
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

803 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