I'm really new to C++, but not to programming, and don't really know what I'm doing. I had a bunch of programs working OK. Then I was messing with a window application and all my window programs would no longer compile.

I get the following error (same for all projects)
c:\program files\microsoft visual studio\vc98\include\winnt.h(1094) : error C2146: syntax error : missing ';' before identifier 'KSPIN_LOCK'
c:\program files\microsoft visual studio\vc98\include\winnt.h(1094) : fatal error C1004: unexpected end of file found

I may (I don't know :) ) have messed with the API settings. There's lot's of references to this on 'google search' but I could find nothing that addressed this specific problem. Any help would be greatly appreciated.

Dani AI

Generated

Good catch, — and good advice from to check for simple syntax mistakes. For anyone landing here later: that C2146/C1004 combo usually isn't a mysterious compiler bug. It means a required typedef or macro earlier in the headers is missing or broken, so the compiler hits a token like KSPIN_LOCK and says “I expected a semicolon before that.” In this case removing or corrupting Basetsd.h (a Platform/SDK/DDK header that supplies pointer-sized typedefs and related macros) will make winnt.h and other Windows headers stop compiling and produce the exact errors shown in the thread.

Practical troubleshooting steps:

  • Generate the preprocessed file to see the include chain and the expanded content (in VC6: Project → Settings → C/C++ → Preprocess to a File, or on the command line run cl /P MyFile.cpp).
  • Search your include paths for a missing or duplicate basetsd.h (for example, dir /s C:\basetsd.h from a cmd prompt).
  • Inspect the preprocessed winnt.h around the reported line to see which typedef or symbol is undefined; that points to the missing header.

Quick fixes and precautions:

  • Restore Basetsd.h from the Platform SDK, DDK/WDK, or a working machine. Reinstall or repair the SDK/VC install if needed.
  • Make sure you do not have a stray copy of system headers inside your project folder that shadow the real SDK headers. In VC6 adjust Include directories (Tools → Options → Directories → Show directories for: Include files) so the correct SDK comes first.
  • Note: KSPIN_LOCK is a kernel-mode construct; if a user-mode project is pulling kernel headers, check why those includes were added.

Final note: the root cause here was a deleted system header rather than a brace mismatch, but both are reasonable first checks — syntax errors in your own code and missing/corrupted SDK files are the two most common causes.

Recommended Answers

All 3 Replies

Check that you aren't missing a } or have 2 }} when you should only have 1. I've had silly errors like that give me hundreds of compiler errors..

Thanks for the response...
The compiler does a pretty good job of catching syntax errors and I've checked for anything obvious.

I'm using Micro$ Visual C++ 6.0 and I'm getting the same error on untouched 'wizard' applications. I 'think' I know what the problem is, but I need a file from work to confirm. I'll report back and let you know what transpired.

Talking of VC 6.0, does anyone know if you can turn-on line numbering in the editor. Micro$ frequently hides little things like that. :)

OK! This was my problem.
As stated at the beginning of this thread, I don't know what I'm doing, YET. :)

I downloaded a project from the web which pulled up a dependancy file, Basetsd.h, and I did not know why it was there. (didn't appear with the MS projects !!). So deleted it.
NOT a good idea :rolleyes:

Down to the office, get a copy of the file, install it, and all's well.

The moral: Don't mess with things you don't understand...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.