Solved

Registry keys!

Posted on 1999-01-19
4
227 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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 …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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