user565739
user565739

Reputation: 1332

Windows.h or StdAfx.h, the first window example in Petzold's book "Programming Windows"

I am learning winapi at the beginning from Petzold's book "Programming Windows", 5th edition.

The first example to create a window has a little problem to me. On the book, it's written that

#include "windows.h" (only this one)

But when I use Visual Studio C++ to (under Windows 7 64-bit) compile it, it complains that

Warning 1 warning C4627: '#include "Windows.h"': skipped when looking for precompiled header use

and

Error 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

After I change it to #include "StdAfx.h", it works fine.

So why I can't use Windows.h, and need to use StdAfx.h??

Upvotes: 2

Views: 3560

Answers (2)

Mirza Hammad
Mirza Hammad

Reputation: 1

In this case you want to change your precompiled headers you are using pch:

  1. Go to the solution on the right side of a compiler.
  2. Right click on it,
  3. By clicking this you select the properties.
  4. Then select the configuration properties and select All on the top left corner of a box.
  5. Press ok.
  6. Now select the project and right click on it.
  7. Select the properties option.
  8. Go to configuration and select c/c++ ,click on recomended headers,by clicking this select
  9. Select no precompiled headers.
  10. Press ok

Now your problem is solved

Upvotes: -2

Steve Townsend
Steve Townsend

Reputation: 54148

You have your project configured to use precompiled headers. In that case you put windows.h into stdafx.h, include stdafx.h in all compilation units that use PCH, and all is well. Or, modify your project settings in the IDE to not use Precompiled Headers.

The book apparently assumes no PCH for clarity and independence from IDE vagaries. Using PCH could speed up your build times if you develop large lists of header files, but for now it's probably simpler to not use this.

Upvotes: 4

Related Questions