Solved

Registry keys!

Posted on 1999-01-19
4
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome! It works now! You da man. ;)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

11 Experts available now in Live!

Get 1:1 Help Now