关于"afx.h"头文件

antivice 2009-05-27 09:21:35
我用vc2008新建了一个窗体项目,只写了一句话:#include "afx.h" 运行出错:fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

在项目属性——配置属性 ——常规——MFC的使用——选择“在静态库中使用 MFC” 提示错误:
1>------ 已启动生成: 项目: JLU_DRGS, 配置: Debug Win32 ------
1>正在编译...
1>cl: 命令行error D8016 :“/MTd”和“/clr:pure”命令行选项不兼容
1>项目: error PRJ0002 : 错误的结果2 (从“F:\Microsoft Visual Studio 9.0\VC\bin\cl.exe”返回)。
1>生成日志保存在“file://f:\JLU_DRGS\VC\JLU_DRGS\JLU_DRGS\Debug\BuildLog.htm”
1>JLU_DRGS - 1 个错误,个警告
========== 生成: 成功0 个,失败1 个,最新0 个,跳过0 个==========

在项目属性——配置属性 ——常规——MFC的使用——选择“在共享 DLL 中使用 MFC” 提示错误:
1>------ 已启动生成: 项目: JLU_DRGS, 配置: Debug Win32 ------
1>正在编译...
1>stdafx.cpp
1> WINVER not defined. Defaulting to 0x0600 (Windows Vista)
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxv_w32.h(247) : error C3641: “DrawState”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxv_w32.h(265) : error C3641: “DrawStatusText”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2534) : error C3641: “FreeResource”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxv_w32.h(279) : error C3641: “UnlockResource”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(90) : error C3641: “InterlockedExchangePointer”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(102) : error C3641: “ATL::_AtlGetConversionACP”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(535) : error C3641: “AtlA2WHelper”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(554) : error C3641: “AtlW2AHelper”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(572) : error C3641: “AtlA2WHelper”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(577) : error C3641: “AtlW2AHelper”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(530) : error C3641: “AtlDevModeW2A”: 用 /clr:pure 或 /clr:safe 编译的函数的调用约定“__stdcall ”无效
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(65) : error C2440: “default argument”: 无法从“int (__cdecl *)(int,const char *,int,const char *,const char *,...)”转换为“ATL::CTrace::fnCrtDbgReport_t”
1> 使用 /clr:pure 和 /clr:safe 时,函数地址服从 __clrcall 调用约定;请考虑在目标类型中使用 __clrcall
1>F:\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(146) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译
1>生成日志保存在“file://f:\JLU_DRGS\VC\JLU_DRGS\JLU_DRGS\Debug\BuildLog.htm”
1>JLU_DRGS - 13 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========


继续帮助,不胜感激
...全文
5226 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hei__zi__ 2012-05-17
  • 打赏
  • 举报
回复
楼主 解决了没啊?我现在也遇到了这个问题 没地着手啊
zlyp_zl 2011-12-29
  • 打赏
  • 举报
回复
在项目属性—“常规”里面,把“公共语言运行库支持”改一下试试,不用pure和safe。
supyhy 2011-10-08
  • 打赏
  • 举报
回复
写出程序

VC++2008:

打开工程后,点击“工程”-右击-“属性”,在打开的对话框中切换到“配置属性"选项卡,将其中的“MFC的使用"设置为"在共享DLL中使用MFC",确定即可
supyhy 2011-10-08
  • 打赏
  • 举报
回复
#include "afx.h"改成#include "stdafx.h"
真相重于对错 2009-05-31
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zfs2008zfs 的回复:]
按照楼上的方法试了,编译通过,运行时弹出一个对话框:
Debug Assertion  Failed!
Program:...\Visual studio2088\Projects\filesearch\Debug\filesearch.exe
File:f:\dd\vctools\crt_bld\self_x86\crt\src\dgb.heap.c
Line:1511

Expression:_CrtIsValidHeapPointer(0UserData)
后面的错误信息就不贴出来了
[/Quote]
你的代码有问题
antivice 2009-05-31
  • 打赏
  • 举报
回复
按照楼上的方法试了,编译通过,运行时弹出一个对话框:
Debug Assertion Failed!
Program:...\Visual studio2088\Projects\filesearch\Debug\filesearch.exe
File:f:\dd\vctools\crt_bld\self_x86\crt\src\dgb.heap.c
Line:1511

Expression:_CrtIsValidHeapPointer(0UserData)
后面的错误信息就不贴出来了
antivice 2009-05-31
  • 打赏
  • 举报
回复
我新建的windows窗体项目,只写一句代码::#include "afx.h"
真相重于对错 2009-05-30
  • 打赏
  • 举报
回复
1>cl: 命令行error D8016 :“/MTd”和“/clr:pure”命令行选项不兼容
编译选项用clr不要用clr:pure
antivice 2009-05-30
  • 打赏
  • 举报
回复
高手哪里去了?急需帮助啊
antivice 2009-05-29
  • 打赏
  • 举报
回复
呜呼哀哉!竟无人能解决此问题?
ai_li7758521 2009-05-28
  • 打赏
  • 举报
回复
关注
antivice 2009-05-28
  • 打赏
  • 举报
回复
在项目属性——配置属性 ——常规——MFC的使用——选择“在共享 DLL 中使用 MFC

至于这种解决方案,试过了,错误列在上面
antivice 2009-05-28
  • 打赏
  • 举报
回复
#include <afx.h> 和#include "afx.h"两种写法都出错,问题不在于此
pigpy 2009-05-28
  • 打赏
  • 举报
回复
很简单,AFX.H是系统文件,你include的时候应该用<>。

#include <afx.h>

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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