Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
visualc++; < >下面的C++代码有一些问题_C++_Windows_Visual Studio 2008_Visual C++_Mfc - Fatal编程技术网

visualc++; < >下面的C++代码有一些问题

visualc++; < >下面的C++代码有一些问题,c++,windows,visual-studio-2008,visual-c++,mfc,C++,Windows,Visual Studio 2008,Visual C++,Mfc,我正在使用VC++,现在我正在尝试编译以下基于MFC的项目 这是一个源文件winmfcproectum.cpp 这些是头文件 stdafx.h 我在共享DLL中使用MFC创建了非空Win32项目 resource.h和targetver.h是自动创建的,我不在这里发布它们。 因为stdafx.h是预编译的,所以stdafx.cpp也是自动创建的 现在我的问题是,看起来COurApp类在winmfcproectum.cpp中是不可见的,尽管我已经包括了winmfcproectum.h,所以如果我评

我正在使用VC++,现在我正在尝试编译以下基于MFC的项目

这是一个源文件winmfcproectum.cpp

这些是头文件

stdafx.h

我在共享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

正如链接器所说,它无法从MFC中找到类,如果你真的链接到正确的MFC库,你应该仔细检查你的项目设置。

Aha,现在我明白了。我的项目和正在工作的项目之间的唯一区别是,正常工作的项目在其“字符集”选项字段中有“多字节字符集”,而我的项目有“unicode字符集”。因此,上面所有这些错误都是针对unicode字符集编译的结果


有趣的是,即使不向任何函数传递任何字符串,也不可能为unicode字符集编译,尽管例如,他们说如果我们要为unicode字符集编译,我们可以在字符串前面加上L或泛型_t()宏。至少,我在我的VC++上尝试过这个,但没有成功。

我的系统上只有一个MFC库,它工作正常,因为我用它测试了另一个MFC项目。正确指定了指向mfc includes/libs的路径,不需要其他依赖项,创建项目以在共享DLL中使用mfc。还有什么需要检查的?你也看了吗?同样,链接器抱怨要找到每个方法的版本,这些方法采用
wchar
而不是
char
。嗯,他们说MFC动态链接库的unicode版本是
mfc80u.lib
mfcs80u.lib
,但我的库是
mfc42u.lib
mfcs42u.lib
。这就是我无法编译unicode字符集的原因吗?对于VS8,您甚至应该在安装中找到
mfc90xxx.lib
?!看。哈哈,实际上我使用的是VC++2008快速版,它缺乏MFC支持,所以我不得不下载winDDK并使用它的MFC42库。我仍然可以成功地编译多字节字符集。
// 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
#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
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