在用MFC向导生成的对话框程序中,加入了ATL支持,ATL向导生成了如下代码
// 我加的
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400// ATL加的
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
class CTestmycom1Module : public CComModule
{
public:
LONG Unlock();
LONG Lock();
LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2);
DWORD dwThreadID;
};
extern CTestmycom1Module _Module;
#include <atlcom.h>但向导增加的如下代码通不过
BOOL CTestmycom1App::InitATL()
{
m_bATLInited = TRUE;#if _WIN32_WINNT >= 0x0400
HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
HRESULT hRes = CoInitialize(NULL);
#endif
........
}
错误提示为:error C2065: 'CoInitializeEx' : undeclared identifier
查MSDN也查不出名堂来,请高人指点,是不是MFC和ATL什么地方起冲突了?

解决方案 »

  1.   

    Header: Declared in objbase.h.
    Import Library: Included as a resource in ole32.dll.加个
    #include <objbase.h>  试试
      

  2.   

    Requirements 
      Windows NT/2000/XP: Requires Windows NT 4.0 or later.
      Windows 95/98: Requires Windows 98 (or Windows 95 with DCOM).
      Header: Declared in objbase.h.
      Library: Use ole32.lib.
      

  3.   

    不要使用CoInitializeEx,用这个试试:
    //初始化
    HRESULT hr;
    hr = CoInitialize(NULL);
    if (FAILED(hr))
    {
    AfxMessageBox("error");
    //exit(hr);
    }
      

  4.   

    在你前面的定义前加上STRICT,在后面加上endif
    如:
    #define STRICT        
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0400
    #endif
      

  5.   

    #define _WIN32_WINNT 0x0400放在最首
      

  6.   

    看看这个定义就知道了 :
    #if (_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) // DCOM
    WINOLEAPI  CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
    #endif // DCOM添加:
    #ifndef _WIN32_DCOM
    #define _WIN32_DCOM
    #endif
    或定义_WIN32_WINNT
      

  7.   

    可能是在CoInitialize之前,调用了AfxInitOle()函数。
    重复初始化会出问题。
      

  8.   

    在VC中设置:
    “Project” -->> “Setting...” -->> “C/C++” -->> 选择ListCombo中的“precompiled headers-->> Not using precompiled headers.
      

  9.   

    #ifndef _WIN32_DCOM
    #define _WIN32_DCOM  //下面包含文件之前加
    #include <objbase.h>