tags:

views:

270

answers:

7

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.

+2  A: 

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.

Jasper Bekkers
+1  A: 

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

Kip
+2  A: 

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.

David Dibben
A: 

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.

graham.reeds
I'm more interested in spooler.h; without seeing full compiler output, I'm guessing that's where the issue is. Especially if it happened on a new scratch project. Like others have said, I'm sure it's just an unbalanced parenthesis.
John Rudy
If the error is occurring at the indicated line, my first guess is that ID_SPOOLER_EVENT is a macro with an unmatched paren in it. Crazy as that sounds...
Steve Jessop
@onebyone: That would absolutely make sense; hence why I want to see spooler.h, which is where I think said macro is #defined.
John Rudy
Yeah, the only difference is that I don't want to see spooler.h, I want my guess to be correct and the questioner to look at it for me and tell me so ;-)
Steve Jessop
@onebyone: Touche!
John Rudy
You were right - in the test program I used a #define, but in the main program I have a bunch of messages contained in an enum. I had stupidly put a semi-colon on it and even more stupidly failed to see it. Leave me alone - it's a friday...
graham.reeds
+9  A: 

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.

Michael Burr
Not strictly necessary to compile preprocessed file, VC has "Preprocess to file with line numbers" option.
Constantin
+1  A: 

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.

David Thornley
A: 

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.

crashmstr