?
Solved

Registry keys!

Posted on 1999-01-19
4
Medium Priority
?
232 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
[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
  • 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

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