我对以下 C++ 代码有一些问题
我正在使用 VC++,现在我正在尝试编译以下基于 MFC 的项目
这是一个源文件winmfcproectum.cpp
#include "stdafx.h"
#include "winmfcproectum.h"
// ExX112_021.CppPP
// An elementary MFC program
COurApp::COurApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
COurApp AnApplication; // Define an application object
// Function to create an instance of the main application window
BOOL COurApp::InitInstance()
{
// AfxEnableControlContainer();
// Construct a window object in the free store
// m_pMainWnd = new COurWnd;
// m_pMainWnd->ShowWindow(m_nCmdShow); // ...and display it
return TRUE;
}
这些是头文件,
标准数据文件
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
和winmfcproectum.h
#ifndef _WINMFCPROECTUM_H
#define _WINMFCPROECTUM_H
#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
class COurWnd : public CFrameWnd
{
public:
// Constructor
COurWnd()
{
Create(0, L"Our Dumb MFC Application");
}
};
// Application class definition
class COurApp : public CWinApp
{
public:
COurApp();
public:
virtual BOOL InitInstance();
};
#endif
我在共享 DLL 中使用 MFC 创建了非空 Win32 项目,
resource.h和targetver.h是自动创建的,我不在这里发布它们。
因为stdafx.h是预编译的,所以stdafx.cpp也是自动创建的
现在我的问题是,看起来COurApp类在winmfcproectum.cpp中是不可见的,尽管我已经包含了 winmfcproectum.h,所以如果我评论那些构造函数和函数实现,即COurApp::COurApp()和COurApp::InitInstance(),以及它们之间的变量声明,一切都编译得很好
这是编译输出:
Compiling...
winmfcproectum.cpp
Linking...
winmfcproectum.obj : error LNK2019: unresolved external symbol "public: __thiscall CWinApp::CWinApp(wchar_t const *)" (??0CWinApp@@QAE@PB_W@Z) referenced in function "public: __thiscall COurApp::COurApp(void)" (??0COurApp@@QAE@XZ)
winmfcproectum.obj : error LNK2001: unresolved external symbol "public: virtual class CDocument * __thiscall CWinApp::OpenDocumentFile(wchar_t const *)" (?OpenDocumentFile@CWinApp@@UAEPAVCDocument@@PB_W@Z)
winmfcproectum.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CWinApp::AddToRecentFileList(wchar_t const *)" (?AddToRecentFileList@CWinApp@@UAEXPB_W@Z)
winmfcproectum.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWinApp::DoMessageBox(wchar_t const *,unsigned int,unsigned int)" (?DoMessageBox@CWinApp@@UAEHPB_WII@Z)
winmfcproectum.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWinApp::OnDDECommand(wchar_t *)" (?OnDDECommand@CWinApp@@UAEHPA_W@Z)
C:\Documents and Settings\Mango\My Documents\Visual Studio 2008\Projects\winmfcproectum\Debug\winmfcproectum.exe : fatal error LNK1120: 5 unresolved externals