Link to home
Start Free TrialLog in
Avatar of VisualLR
VisualLR

asked on

Using the Registry with MFC.

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 ??
Avatar of chensu
chensu
Flag of Canada image

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

Avatar of VisualLR
VisualLR

ASKER

I had already read that in the MSVC documentation. I turned to this site because it wasn't clear enough for me.
So, which is not clear for you?
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.
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


ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
checkout www.codeguru.com  there is a registry class you can use that wraps the api calls.
Thanks! With you example I was able to make it. Thanks a lot.