batuman
batuman

Reputation: 7304

How to access static variable from Dialog header file in MFC

CDialogI have static int mStatus; in CDialogDlg.h. I like to access that static variable from another cpp file, for example test.cpp. Normally is we access static variable as CDialogDlg::mStatus = 1. But when I include CDialogDlg.h into test.h, I got two compilation errors as

 Error 1: error C2504: 'CDialogEx' : base class undefined

 Error 2: error C2065: 'IDD_CDialog_DIALOG' : undeclared identifier

Why I can't include CDialogDlg.h into test.h. I am not very familiar with MFC. Thanks.

Upvotes: 1

Views: 1810

Answers (1)

Blacktempel
Blacktempel

Reputation: 3995

As the #include "resource.h" is usually included by default in your header file CMyNameApp.h it should have been #include <afxdialogex.h>. Even though you could have deleted #include "resource.h" from the header, so you would have to include it again.

#include "resource.h"
#include <afxdialogex.h>

Should solve your whole problem.

Upvotes: 4

Related Questions