Saturday, February 10, 2018
tips and tricks on pre-compiled header. my note is taken from the following posts.
- Precompiled headers
First, make sure you select "All Configurations" so that your fixes will affect both debug and release builds of your project.
Now, go to the C/C++ tab, precompiled headers category. Select "Use precompiled header file" and type in the name of your precompiled header file (stdafx.h or precompiled.h).
If you try to build now your build will fail, giving a cryptic error about how it doesn't know how to create the .pch file. You need to tell it how.
In the explorer view in project settings, open up your project and navigate down to the .cpp file that you chose for creating the precompiled header file (in VS.Net you will select that file from the Solution Explorer).
Select that file, with "All Configurations" still selected, and select "Create precompiled header file", and type in the name of your precompiled header file.
It kind of makes sense once you go through the steps. You give VC++ one source file to create the precompiled header file, and the other files all use it. This guarantees that it won't be rebuilt unnecessarily.
You have to #include this file from all of your source files so that if you turn precompiled headers off, your program will compile in the same manner.
The one fly in the ointment, the worrisome aspect of this feature, is that there is actually no guarantee that your program will behave identically, because VC++ doesn't enforce that your #include of the precompiled header file comes first. It enforces that you include the precompiled header file in each source file, but it will happily ignore includes, defines, and other code before that include. If you notice yourself getting some strange errors after changing your precompiled header files, that's probably why.
Go through all of your source files and make sure that your precompiled header file is included first.
That's it. If you have any problems then double check all of the steps, check the problematic source files for any preprocessor directives or code before the include of the precompiled header file, and maybe do a rebuild-all for good measure. If you want an example of a properly setup project to use as a reference, use the AppWizard to create an MFC project.
You may be surprised. With Visual Studio .Net you can get a hierarchical list of header files used by setting Properties->C/C++->Advanced->Show Includes to yes.
- Speed up C++ compilation, part 1: precompiled headers
With Visual C++ 6.0 you have to run devenv.exe with the undocumented /y3 option.
In Visual Studio .Net you can get similar functionality by going to Tools->Options->Projects->VC++ Build and setting Build Timing to Yes.
add some variation on this line to all copies of windows.h on my machine:
#pragma message("Compiling windows.h - this should happen just once per project.\n")
Setting up precompiled headers
The only precompiled header settings that are efficient to use are the Create/Use pair of settings.( The documentation for these settings tells you what each setting does, but it fails to give you the big picture - it doesn't tell you how to setup a project to use these two together.)
The basic idea is that one cpp file is specified as creating the precompiled header file and the other cpp files uses that precompiled header file. Because only one source file ever creates the precompiled header file it is guaranteed that it will only get built once per total rebuild.
First you need to have one header file that every source file in your project will include. This is typically called stdafx.h or precompiled.h. If you don't have such a file, create it now. Check it to make sure it is including the appropriate set of header files - big header files that never change. Now make sure that every source file in your project is including this header file as the first non-comment thing that they do.
Now you need one source file whose only job is to create the precompiled header file. It's best to have a source file exclusively for this purpose because every time this source file is modified, the .pch file will be regenerated. Generating the .pch file is an expensive operation that we are trying to avoid. This source file will typically be called stdafx.cpp or precompiled.cpp - to match the header file.
Now it's time to go to project settings.
The defaults are dangerous
For some projects - typically non-MFC projects, but the specifics depend on what version of VC++ you are using - the project wizard's set the precompiled header option to the seductive sounding "Automatic use of precompiled headers." Microsoft itself has admitted that this option is inefficient - yet they make it the default for many projects. Unless you are exquisitely careful this "automatic" use of precompiled headers translates to "rebuilding the precompiled headers for every source file." It is difficult to avoid this and keep it working properly. Don't use it. Either disable precompiled headers, or use them properly.
If you use the DirectX AppWizard to create a non-MFC project, the newly created project will use the "Automatic use of precompiled headers" setting. Because of this these projects will take approximately twice as long to build as they need to. You need to manually fix them to get good build performance.
Friday, February 9, 2018
- Five PE Analysis Tools Worth Looking At
- PE Format
- Windows Programming Utilities
- Code Obfuscation in 64-Bit Land
- TinyPE NG
- COMPILER, ASSEMBLER, LINKER AND LOADER: A BRIEF STORY
- Microsoft Visual Studio
- A Number of Reusable PE File Format Scanning Functions
- Principled, lightweight C/C++ PE parser
- Portable Executable (PE) library written in .Net
- OpenRCE Articles
a very good introduction. PEBrowse is a good tool.
good time to research on API stuff.
Saturday, February 3, 2018
very good tips from a phd student
- MVP Tips, Techniques, and Goodies
- C# for MFC programmers Quick Equivalents Map
- Character Functions
- Drawing Techniques
- Hooks and DLLs
- A Logarithmic Slider Control
- The PolyDraw Explorer
- Virtual Screen Coordinates
- Limiting Window Resizing Resizing Controls
- The NUMA Explorer
- A General Polygon Management Routine
- Sharp Layout
- Automatic Layout of Resizable Dialogs
- Layout Manager for Dialogs, Formviews, DialogBars and PropertyPages
this post is very important for me expand my windows form to multi-screen setting.