开发者

How to not #include <windows.h>

开发者 https://www.devze.com 2023-01-03 04:23 出处:网络
Using MSVC2008, 32bit on 64bit system. I was once advised to never include windows.h as \'its a real monster and will slow down my compile times significantly\'.

Using MSVC2008, 32bit on 64bit system.

I was once advised to never include windows.h as 'its a real monster and will slow down my compile times significantly'.

I tried leaving it out and obviously get compile errors. I included windef.h to define all the 开发者_运维知识库DWORDs etc, but I quickly come unstuck knowing what else to define to get the code to compile.

I now get:

2>c:\program files\microsoft sdks\windows\v7.0\include\winnt.h(6361) : error C2146: syntax error : missing ';' before identifier 'ContextRecord'
2>c:\program files\microsoft sdks\windows\v7.0\include\winnt.h(12983) : error C2065: 'PCONTEXT' : undeclared identifier

Can anyone suggest the right approach here?

Thanks

Simon


Use precompiled headers to improve compile times, and include windows.h.


Internally, windows.h respects many defines, like NOMINMAX or WIN32_LEAN_AND_MEAN.

It reduces the times significantly.


The correct answer would be "include it in the PCH". Pre-compiled headers reduce compilation time dramatically, and, contrary to popular belief, this is true also for Full Rebuilds.

If you have more than one CPP file in your project, the "Rebuild all" would build it once for the whole project, which merely ads a few seconds to compile time - to have windows.h included in all of them.


Research the APIs and make sure the headers are included in the correct order. It's not hard to not use Windows.h; but you'll learn about the MS headers in the process.

There are a few headers you have to be aware of:

WTypes.h
WinDef.h
WinBase.h
WinObject.h
0

精彩评论

暂无评论...
验证码 换一张
取 消