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
Solved

Registry keys!

Posted on 1999-01-19
4
222 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

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…
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 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 bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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