views:

89

answers:

1

Is it possible to specify the application name which is used by CWinApp::WriteProfileString()?
If I use CWinApp::SetRegistryKey to set the name of my company to "MyCompany", and I call AfxGetApp()->WriteProfileString in my application called "SomeApp", my string will be stored under the following registry key:
HKEY_CURRENT_USER\Software\MyCompany\SomeApp\...

The problem is that my users want to run multiple versions of SomeApp. So in order that the registry settings don't conflict I want to store them in keys like this:
HKEY_CURRENT_USER\Software\MyCompany\SomeApp 1.1\...
HKEY_CURRENT_USER\Software\MyCompany\SomeApp 2.0\...
etc.

I could replace all instances of WriteProfileString with my own function, but this would be quite difficult as it is used extensively in both our source code and some of the third-party libraries that we use.

Is there some way to force WriteProfileString to use a different string for the application name?

+2  A: 

This code in the app constructor worked well:

  free((void*)m_pszProfileName);
  free((void*)m_pszRegistryKey);
  m_pszRegistryKey = _tcsdup(L"nobugz");
  m_pszProfileName = _tcsdup(L"myapp\\1.0");
Hans Passant
Fantastic. The only problem was that I had to put the code in the app's InitInstance - putting it the constructor didn;t work.Thanks very much!
Hoppy