Solved

Customizing CWinApp's Registry Functionality

Posted on 1998-07-28
5
816 Views
Last Modified: 2013-11-20
I am trying to customize the registry functionality of CWinApp. To do this I am trying to derive another App class from it. I have overriden the GetAppRegistryKey(), GetSectionKey(), and SetRegistryKey() functions so far. I am then trying to use WriteProfileString() to write to a key that is under HKEY_LOCAL_MACHINE. I have not been able to write to anything except the HKEY_CURRENT_USERS hive. Is there a way to do this without resorting to using just the WIN32 API? If so what? Am I missing something obvious? Also would there be any problem putting this class derived from CWinApp into a DLL. If more detail is needed I can supply it.
0
Comment
Question by:awd
[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
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 1319857
I hope i got your question right ...
If i were you i would use the registry functions,
::RegOpenKeyEx(..), ::RegSaveKey(..) and so on.
These functions seem very difficult if you get the first time in
touch with them, but after a short time you will realize that
it is not a bit more complicated than using WriteProfileString()
and so on.
To your second question: This is possible(MFC Extension DLL), but
has the disadvantage that your AppWizard won't create an application
using your dll.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1319858
Short example to save a value in the registry:

HKEY hkey;
::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
               "Software\\myCorp\\myKey",
               0,KEY_ALL_ACCESS,&hkey);
CString test="Registry test."
::RegSetValue(hkey,"Program Name",REG_SZ,
              (LPCTSTR)test,test.GetLength());
::RegCloseKey(hkey);
0
 
LVL 1

Author Comment

by:awd
ID: 1319859
Thanks for the example. It complements the online help very well! I may end up doing it this way. I would like to do it by overriding the CWinApp functionality first (to make sure I have learned the concept) and then decide which way is better.

There aren't any problems trying to derive another class from CWinApp in an extension DLL? It seems like that could be a special case. I have been having trouble getting AfxGetApp() to return a reference to the derived App class insted of the CWinApp class.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1319860
>> I have been having trouble getting AfxGetApp() to return a reference to the derived App class instead of the CWinApp class

You are right, i forgot that. But i think the only way to alter this behavior is to recompile the MFC.
Look at this piece of sourcecode:

_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp()
{ return afxCurrentWinApp; }

It is defined as inline function - to override it had to be a virtual function. Because AfxGetApp()
is used internally by the MFC, the only way would be to recompile, i think.
An other way could be - which is not enough, i think - to just override the virtual functions of
CWinApp. Or - when you need the special behavior your class implements - you define a
macro like:

#define AfxGetExtApp() ((CMyWinApp*)AfxGetApp())

and use this to access the special member functions.
I am sorry, but i do not see an other way. Let's see if someone provides you an easier answer
to this.
0
 
LVL 1

Author Comment

by:awd
ID: 1319861
Thank you VERY much for your time and the help you supplied! With it I was finally able to get everything working the way I had originally tried. I was able to derive a class from CWinApp and override (if that is the correct terminology)  the relevant functions to change the way it handled the registry. And I was able to get it working after defining it in an MFC Extension DLL.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 35
has77  challenge 9 107
Use of condition with 'serial' in ansible 2 103
Fibonacci challenge 11 141
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

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