Build using the /P option, which will create a preprocessed file (usually with the .i extension).
In Visual Studio, the option will be on the properties for the project under something like:
C/C++ - Preprocessor - Generate Preprocessed File
With that you can see exactly how macros are being expanded. You may need to run the .i file through the compiler to find the exact line that causes the syntax error. It can be a pain to read the post-preprocessed file, but it should show what's going on.
Without the source it is hard to be sure exactly what is happening. From the first part of your question it seems like this particular code compiles correctly in the project where it was first used, but when you include it in your second project it no longer compiles. If this is the case you want to look at what other headers are included before this one. Sometimes, if your function or variable names are the same as something defined in another header, especially windows.h, then you can get errors from code which previously compiled without problem.
If this code has never compiled correctly, then the other answers suggesting you check the opening/closing "(" are probably the place to start.
你需要找出事物扩展到什么。 特别是,ID_SPOOLER_EVENT 是什么? 如果它有不平衡的括号,那就是你的罪魁祸首。 如果没有,那么就听从 Mike B 的建议吧。 对我来说这看起来像是一个预处理器问题。
You need to find out what things expand to. In particular, what is ID_SPOOLER_EVENT? If it has unbalanced parentheses, that's your culprit. If not, well, go with Mike B's advice. This looks like a preprocessor issue to me.
// the only two includes
#include <windows.h>
#include "spooler.h"
// in WinMain
// create window then...
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
SpoolerInitiallize( hwnd, ID_SPOOLER_EVENT ); // <-- our function
...
// the only two includes
#include <windows.h>
#include "spooler.h"
// in WinMain
// create window then...
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
SpoolerInitiallize( hwnd, ID_SPOOLER_EVENT ); // <-- our function
...
And yes, I know it is spelt wrongly and the word initialise is spelt wrongly throughout the documentation too. Unfortunately it can't be changed as we also supply this dll to third parties.
That suggestion reminded me why that error looked so familiar. For me, it was a very short #define that was replacing a variable name with an literal int or something like that. Nasty.
Running the code through the preproccessor is how I found out what was happening.
发布评论
评论(7)
使用 /P 选项构建,这将创建一个预处理文件(通常带有 .i 扩展名)。
在 Visual Studio 中,该选项位于项目的属性上,如下所示:
通过该选项,您可以准确地看到宏是如何扩展的。 您可能需要通过编译器运行 .i 文件以找到导致语法错误的确切行。 读取预处理后的文件可能很痛苦,但它应该显示发生了什么。
Build using the /P option, which will create a preprocessed file (usually with the .i extension).
In Visual Studio, the option will be on the properties for the project under something like:
With that you can see exactly how macros are being expanded. You may need to run the .i file through the compiler to find the exact line that causes the syntax error. It can be a pain to read the post-preprocessed file, but it should show what's going on.
这与包含文件的方式没有任何关系,这是一个语法错误,因为您没有正确嵌套
(
和)
。This doesn't have anything to do with the way you include files, it's a syntax error that you get because you didn't nest
(
and)
correctly.如果没有消息来源,很难确定究竟发生了什么。 从问题的第一部分来看,这个特定的代码似乎在第一次使用它的项目中正确编译,但是当您将它包含在第二个项目中时,它不再编译。 如果是这种情况,您需要查看在此标题之前还包含哪些其他标题。 有时,如果您的函数或变量名称与另一个头文件中定义的名称相同,尤其是 windows.h,那么您可能会从之前编译没有问题的代码中得到错误。
如果此代码从未正确编译,那么建议您检查开始/结束“(”的其他答案可能是开始的地方。
Without the source it is hard to be sure exactly what is happening. From the first part of your question it seems like this particular code compiles correctly in the project where it was first used, but when you include it in your second project it no longer compiles. If this is the case you want to look at what other headers are included before this one. Sometimes, if your function or variable names are the same as something defined in another header, especially windows.h, then you can get errors from code which previously compiled without problem.
If this code has never compiled correctly, then the other answers suggesting you check the opening/closing "(" are probably the place to start.
你的编译器应该告诉你错误发生在哪一行。 尝试在该行末尾搜索前一个“(”。
Your compiler should tell you what line the error was on. Try searching for the previous "(" before the end of that line.
你需要找出事物扩展到什么。 特别是,ID_SPOOLER_EVENT 是什么? 如果它有不平衡的括号,那就是你的罪魁祸首。 如果没有,那么就听从 Mike B 的建议吧。 对我来说这看起来像是一个预处理器问题。
You need to find out what things expand to. In particular, what is ID_SPOOLER_EVENT? If it has unbalanced parentheses, that's your culprit. If not, well, go with Mike B's advice. This looks like a preprocessor issue to me.
正在使用的代码:
是的,我知道它拼写错误,并且整个文档中的“初始化”一词也拼写错误。 不幸的是,它无法更改,因为我们还向第三方提供此 dll。
The code that is being used:
And yes, I know it is spelt wrongly and the word initialise is spelt wrongly throughout the documentation too. Unfortunately it can't be changed as we also supply this dll to third parties.
尝试一下 Mike B 对预处理器所说的内容。
这个建议让我想起了为什么这个错误看起来如此熟悉。 对我来说,这是一个非常短的#define,它用文字 int 或类似的东西替换变量名。 可恶的。
通过预处理器运行代码是我发现发生了什么的方法。
Try what Mike B said with the preprocessor.
That suggestion reminded me why that error looked so familiar. For me, it was a very short
#define
that was replacing a variable name with an literal int or something like that. Nasty.Running the code through the preproccessor is how I found out what was happening.