3

Building correctly a C++/ATL project : I'm trying to use my MFC code into an ATL (Service EXE) project. In which, I've included all my Existing Items. When I've configured the project to Use MFC in a Shared DLL, I've had this error message while debugging :

error C2039: 'CAtlServiceModuleT' : is not a member of 'ATL'.

And, the debugger had underlined the marked line :

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;

How do I fix it, please ?

You can find here my 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>

Thanks a lot !!

Lucie kulza
  • 1,357
  • 6
  • 20
  • 31

1 Answers1

0

The major problem is that you mix two similar things with different concepts.

MFC and the ATL provides a way for base classes to support internal program functions (message loop, registration etc.).

If you include the MFC headers first the classes for the modules (including the CAtlServiceModuleT template) are excluded. You see an #ifndef _AFX in the header files.

You can solve this in first including the atl headers. But than you need to #undef WINDOWS before you include tha afx.h header. But this is a hack!

Maybe the better way is to use the MFC framework as base classes. The reason is simple: Most of the MFC relays of an existing CWinApp... so you need this. But when you use this you don't need the CAtlServiceModuleT any longer!

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • 2
    Thanks for your response, it's interesting to know. Can you please tell me why it's a `hack` ? – Lucie kulza Feb 14 '14 at 13:09
  • It is a hack, because MFC headers include the Windows Header per default. Now the Header are includes twice because the guard is undefined. The best way wouldbe to use the MFC as the main instance and to includde the ATL parts into it. As I wrote: The MFC works only with a CWinApp. So you Need it. So why should you use the ATL module? – xMRi Feb 15 '14 at 11:57
  • 2
    I need to run the app as a Service and optimize its use of RAM. – Lucie kulza Feb 15 '14 at 21:45
  • And why do you Need the MFC Framework AND the ATL Framework. If it is a service you find framewoeks for it at http://www.naughter.com/serv.html. I don't understand why you Need to mix up this all? – xMRi Feb 16 '14 at 12:19
  • in case I change the order and first include atl I get "E0266 'CString' is ambiguous", how do I solve this? – Daniel W. Nov 19 '18 at 13:08