
Static Function & MainFrame
Quote:
> > In my MFC application, it was necessary for me to make a static
function
> in
> > the main window class of the application. From this static function, I
> need
> > to call a nonstatic function in the main window object, but I get an
> error
> > from the compiler. I tried to get a pointer to the main window using
> > AfxGetMainWnd(), but it only returns a pointer to a CWnd* . Since my
> main
> > window is derived from CWnd, I was unable to call the nonstatic
function.
> > Is there any way to obtain a pointer to the main window derived from
CWnd
> > without passing a pointer to it to the static function?
> Yes. Lines marked with >>> differ from AppWizard generated code:
> >>> static CMyFrame* pFrame = NULL;
> >>> static MyFunc ()
> >>> {
> >>> pFrame->MyFrameFunc ();
> >>> }
> BOOL CMyApp::InitInstance ()
> {
> :
> :
> m_pMainWnd = new CMyFrame;
> >>> pFrame = m_pMainWnd;
> }
This would be OK ... only CMyFrame and CMyApp normally reside in different
source files. Modify the declaration of pFrame to look like this:
(in MYFRAME.CPP:)
extern CMyFrame* pFrame = NULL;
(in MYFRAME.H:)
extern CMyFrame* pFrame;
Please repost or email if it doesn't work.
Juergen
----------------------------------------
****** REMOVE THE .NOSPAM TRAILER ******
----------------------------------------
When a person experiences something that
can't be explained within the scientific
world model, the sensible reaction would
be to re-evaluate the world model rather
than denying the experience.
-JMV-
----------------------------------------
****** REMOVE THE .NOSPAM TRAILER ******
----------------------------------------