[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using the Registry with MFC.

Posted on 1998-06-04
8
Medium Priority
?
242 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

649 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