Solved

Registry keys!

Posted on 1999-01-19
4
219 Views
Last Modified: 2013-11-20
I want to set and recall registry keys. I want to recall them obviously when the program first starts up and then write the keys just before the window closes. How do I do this!!! The registry functions are included in CWinApp and I cannot call these functions in my CWnd class because I cannot declare a second CWinApp and get away with it. I created a dialog based MFC shared dll project. There is just one main dialog to my program and I want to be able to use the registry to store my windows position. Any suggestions?
0
Comment
Question by:ducktape
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1327987
You don't need to declare another instance of CWinApp. You do need to declare it as extern though. Assuming CMyWinApp is derived from CWinApp, you can use the following:

  extern CMyWinApp theApp;

  BOOL CMyDialog::OnInit()
  {
    theApp.GetProfileInt(...);
    // or any other registry function
  }
  }
0
 

Author Comment

by:ducktape
ID: 1327988
I tried this and the app crashes upon shutdown. I have two classes CMyApp and CMyDialog. Inside CMyApp I put the keyword 'extern' before CMyApp theApp; and then tried to call the member functions of CMyApp from CMyDialog and got an undeclared identifier error when doing so. Is this the way? Or did I do something wrong? Also when I put the keyword 'extern' in front of CMyApp theApp; it made this declaration disapear from the 'global' listing in the 'class view.' I am working with VC++5.0. Any suggestions?
0
 

Accepted Solution

by:
bheld earned 50 total points
ID: 1327989
Try calling AfxGetApp() which returns a CWinApp*.  You may need to cast this to CMyApp using

CMyApp* pApp = ((CMyApp*)AfxGetApp());

you also want to check that AfxGetApp doesn't return NULL
0
 

Author Comment

by:ducktape
ID: 1327990
Awesome! It works now! You da man. ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 283
Best tools for Backup and restore of Wordpress site 6 55
format the code in java 6 86
sumHeights2  challenge 7 88
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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now