Question

I have a problem with a simple included file.

The file being included is in two MFC programs - one of which is a dll, and it also compiles itself into a non-mfc dll.

Recently I was using the larger dll which wraps around the source of the smaller dll when I wanted access to some of the features of the original code that isn't exposed by the larger dll.

Since this was a test I simply added the source to my project and called the functions. I got this error: syntax error : missing ')' before ';'

The file is correctly included, and I have both the .cpp and the .h in the source folder, and within the project but it wouldn't compile.

I eventually created a very small test project, main.cpp, spooler.cpp and spooler.h (the spooler is a wrapper around the comms) and tried to compile that. Same issue.

So I ripped out all the dll related stuff just in case there is a weird issue going on with that and it still won't compile.

I can't think of the life of me what is wrong. Does anyone else have any ideas?

p.s. Jeff you really need to add the ability to attach files because the source would fill up too many screens with data.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Your compiler should tell you what line the error was on. Try searching for the previous "(" before the end of that line.

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 code that is being used:

// 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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top