怎么在 DLL 中使用CDC

tjkl123 2009-01-12 12:47:31
我包含了<afxwin.h>后 提示 fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>

怎么才能在dll中使用cdc 这个类?
...全文
105 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjkl123 2009-01-12
  • 打赏
  • 举报
回复
问题已解决

把#include <afxwin.h> 放到 stdafx.h 的#include <atlbase.h> 上面

然后 把

**.cpp里面的
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
......
}
替换为

class CAtlApp : public CWinApp
{
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAtlApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL

//{{AFX_MSG(CAtlApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CAtlApp, CWinApp)
//{{AFX_MSG_MAP(CAtlApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CAtlApp theApp;

BOOL CAtlApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance, &LIBID_ATLLib);
return CWinApp::InitInstance();
}

int CAtlApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}

参考帖http://topic.csdn.net/t/20050802/15/4183682.html
keven1868 2009-01-12
  • 打赏
  • 举报
回复
把#include <windows.h>挪到#include <afxwin.h>的后面

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧