在用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什么地方起冲突了?
// 我加的
#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什么地方起冲突了?
Import Library: Included as a resource in ole32.dll.加个
#include <objbase.h> 试试
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.
//初始化
HRESULT hr;
hr = CoInitialize(NULL);
if (FAILED(hr))
{
AfxMessageBox("error");
//exit(hr);
}
如:
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#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
重复初始化会出问题。
“Project” -->> “Setting...” -->> “C/C++” -->> 选择ListCombo中的“precompiled headers-->> Not using precompiled headers.
#define _WIN32_DCOM //下面包含文件之前加
#include <objbase.h>