From: http://blog.csdn.net/liyelun/article/details/5416253
今天修改工程,为了提高编译速度,将#inclue<dshow.h>放到了stdafx.h中,然后重新编译工程。结果有两个文件编译没通过,并且导致的编译错误近百个。
觉得奇怪,没有什么大的改动啊,难道是#include<dshow.h>搞的鬼?于是,将这条语句挪回原来的位置,重新编译,通过了。
到底怎么回事?
又把这条语句放入stdafx.h中,重新编译,仔细观察出错编译结果,第一个警告很让人迷惑,warning C4003: not enough actual parameters for macro 'SubclassWindow'
SubClassWindow什么时候成宏了啊,记得是一个函数啊?说不定是编译器的错误,不管了,往下看。下面的看了就头大了,什么BOOL重新定义了,什么RECT定义找不到啊,一大堆根本不可能的错误,难道编译器真的出问题了?
慢着,为什么说SubclassWindow是宏呢?如果编译器真的出问题了,工程中其他使用RECT的文件怎么会顺利编译呢?直觉告诉我,和这个SubclassWindow有关。于是看了另外一个文件的出错信息,第一行是一个相同的warning。搜了一下工程,只有这两个文件用到了subclasswindow,看来罪魁祸首已经找到了。
如何解决呢?
警告信息写着呢,SubclassWindow这个宏的参数不够,看来是有地方把它定义成宏了,那只要加入#undef SubclassWindow应该就可以了。试了一下,果真可以了。
那到底是什么地方重新定义了SubclassWindow呢?在本地是不好找了,上baidu搜了一下,相关资料不多,但刚好有朋友碰到过相同的问题,并且给出了详细的解释,下面那位朋友原文的转发。
原来在一个项目中写好的类,运行一直没有问题。这次为了版本升级,重新包含在新的项目中,编译始终报错:
warning C4003: not enough actual parameters for macro 'SubclassWindow'
pWnd->SubclassWindow(m_hWndHooked);
源码中这句话怎么也通不过,这子类化窗体哪里写错了?反复对比2个版本,没有任何差异阿...
又把类库从头到尾分析了一遍,足足花去3个小时!.... ....从源码到编译环境设置,都没有什么差异阿...
实在想不通.
最后还是在MSDN里找到这个报告:
BUG: C4003: Not Enough Parameters for SubclassWindow Macro
Article ID : 150076
Last Review : September 18, 2003
Revision : 3.0
This article was previously published under Q150076
SYMPTOMS
When compiling a Microsoft Foundation Class (MFC) application that uses the Windowsx.h header file and calls CWnd::SubclassWindow(), you may get the following error:
warning C4003: not enough actual parameters for macro 'SubclassWindow' error C2059: syntax error : ')'
CAUSE
The Windowsx.h file is a header that includes message cracker macros to help programmers write more portable Windows-based applications. The header file contains a preprocessor macro named SubclassWindow. The macro bears the same name as the CWnd::SubclassWindow() member function. The macro has two parameters; the member function has only one parameter. The preprocessor tries to expand the symbol SubclassWindow when it is found.
RESOLUTION
You can un-define the macro as follows:
#undef SubclassWindow
因此,我的项目出错原因也很明显了,因为Dshow.h里面包含了windowsx.h。
总结
l 一定要注意编译器的异常警告信息
l 修改工程配置或者改变文件包含关系的时候,最好能保证每次或者每几次的改动都是可编译的,这样会更容易定位错误。