?
Solved

Using the Registry with MFC.

Posted on 1998-06-04
8
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 400 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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