Solved

Customizing CWinApp's Registry Functionality

Posted on 1998-07-28
5
818 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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