【问题标题】:error: 'CAtlServiceModuleT' : is not a member of 'ATL'错误:“CAtlServiceModuleT”:不是“ATL”的成员
【发布时间】:2014-03-09 15:27:29
【问题描述】:

正确构建 C++/ATL 项目: 我正在尝试将我的 MFC 代码用于 ATL(服务 EXE)项目。其中,我包含了我所有的Existing Items。当我将项目配置为Use MFC in a Shared DLL 时,调试时出现此错误消息:

错误 C2039:“CAtlServiceModuleT”:不是“ATL”的成员。

而且,调试器在标记的行下划线:

class CATLProject6Module : public ATL::CAtlServiceModuleT< CATLProject6Module, IDS_SERVICENAME > //this one
{
public :
    DECLARE_LIBID(LIBID_ATLProject6Lib)
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ATLPROJECT6, "{3A7F25E3-CA7E-4C90-8B37-11DA70E42248}")
        HRESULT InitializeSecurity() throw()
    {
        // TODO : Call CoInitializeSecurity and provide the appropriate security settings for your service
        // Suggested - PKT Level Authentication, 
        // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY 
        // and an appropriate Non NULL Security Descriptor.

        return S_OK;
    }
    };

CATLProject6Module _AtlModule;

请问我该如何解决?

你可以在这里找到我的stdafx.h

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#if !defined(AFX_STDAFX_H__91E578F6_59F0_4867_BDE7_FCC229588C74__INCLUDED_)
#define AFX_STDAFX_H__91E578F6_59F0_4867_BDE7_FCC229588C74__INCLUDED_

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

#define VC_EXTRALEAN        // Exclude rarely-used stuff from Windows headers

#define _WIN32_WINNT 0x0502 //so that I can use ReadDirectoryChanges

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#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


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

#endif // !defined(AFX_STDAFX_H__91E578F6_59F0_4867_BDE7_FCC229588C74__INCLUDED_)


#ifndef STRICT
    #define STRICT
#endif

#include "targetver.h"

#define _ATL_FREE_THREADED

#define _ATL_NO_AUTOMATIC_NAMESPACE

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS  // some CString constructors will be explicit


#define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW

#include "resource.h"
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>

非常感谢!!

【问题讨论】:

    标签: c++ mfc atl stdafx.h


    【解决方案1】:

    主要问题是您将两个相似的事物与不同的概念混合在一起。

    MFC 和 ATL 为基类提供了一种支持内部程序功能(消息循环、注册等)的方法。

    如果首先包含 MFC 标头,则模块的类(包括 CAtlServiceModuleT 模板)将被排除。您会在头文件中看到 #ifndef _AFX。

    您可以首先解决这个问题,包括 atl 标头。但是,在包含 tha afx.h 标头之前,您需要 #undef WINDOWS。 但这是一个 hack!

    也许更好的方法是使用 MFC 框架作为基类。原因很简单:现有 CWinApp 的大多数 MFC 继电器......所以你需要这个。但是当您使用它时,您不再需要 CAtlServiceModuleT!

    【讨论】:

    • 感谢您的回复,很有趣。你能告诉我为什么是hack 吗?
    • 这是一个 hack,因为 MFC 标头默认包含 Windows 标头。现在 Header 包含两次,因为防护未定义。最好的方法是使用 MFC 作为主实例并将 ATL 部分包含在其中。正如我所写: MFC 仅适用于 CWinApp。所以你需要它。那么为什么要使用 ATL 模块呢?
    • 我需要将应用作为服务运行并优化其对 RAM 的使用。
    • 为什么需要 MFC 框架和 ATL 框架。如果它是一项服务,您可以在 naughter.com/serv.html 找到它的框架。我不明白你为什么要把这一切都混在一起?
    • 如果我更改顺序并首先包含 atl 我得到“E0266 'CString' is ambiguous”,我该如何解决?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-23
    • 2020-02-02
    • 2014-08-27
    • 2016-02-15
    • 2021-09-07
    • 2013-08-07
    相关资源
    最近更新 更多