"undeclared identifier"compilation failures with MFC

Reason #1

Look at your STDAFX.H file. You will see the line

#define VC_EXTRALEAN

there. This excludes whole sections of infrequently-used Win32 functionality, so comment it out and rebuild.

Reason #2

Certain functions are only included if the target operating system is WinNT, and even then only if it's NT4 (or later). Put the line

#define _WIN32_WINNT 0x0400

at the _top_ of your STDAFX.H to force the compiler to include the excluded functions. CreateWaitableTimer is a good example of the functions that behave like this, and it commonly comes up in this context on the newsgroups. You can see the exclusion if you look in WINBASE.H where it's declared.

Reason #3 (courtesy of Joseph Newcomer)

You have done the following:

#define _whatever
#include "stdafx.h"

in some module, where the symbol _whatever is one of the symbols that causes certain names to be defined by including windows.h. But in spite of this, the symbols you want are still undefined. Why? Because of precompiled headers. The symbols available to your compilation are made available based on the precompiled header which is in turn based on the compilation of stdafx.h. If the symbols were not visible at that compilation, changing the #define symbols in other modules will have no effect. Go back and add the #define to your compilation of stdafx.h.