error C2065: 'theApp' : undeclared identifier

解决办法一:
在你要访问的地方的 .cpp 文件中加入
extern C***App theApp;

解决办法二:
得到指向app的指针
如 ((C***App *)AfxGetApp())->你的成员变量

我是在主程序的头文件里添加就可以了:

// five.h : main header file for the FIVE application
//

#if !defined(AFX_FIVE_H__0B197DD2_A92A_4BC8_9B02_88A17EC40DBE__INCLUDED_)
#define AFX_FIVE_H__0B197DD2_A92A_4BC8_9B02_88A17EC40DBE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CFiveApp:
// See five.cpp for the implementation of this class
//

class CFiveApp : public CWinApp
{
public:
CFiveApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFiveApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

// Implementation

//{{AFX_MSG(CFiveApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CDatabase m_DB;
};

extern CFiveApp theApp;
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FIVE_H__0B197DD2_A92A_4BC8_9B02_88A17EC40DBE__INCLUDED_)
原文地址:https://www.cnblogs.com/xiaocai0923/p/2255593.html