VC++ 开发笔记
1. Every Windows program includes an entry-point function named either WinMain or wWinMain. The following code shows the signature for wWinMain:
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);
The four wWinMain parameters are as follows:
- hInstance is the handle to an instance or handle to a module. The operating system uses this value to identify the executable or EXE when it's loaded in memory. Certain Windows functions need the instance handle, for example to load icons or bitmaps.
- hPrevInstance has no meaning. It was used in 16-bit Windows, but is now always zero.
- pCmdLine contains the command-line arguments as a Unicode string.
- nCmdShow is a flag that indicates whether the main application window is minimized, maximized, or shown normally.
The WinMain function is the same as wWinMain, except the command-line arguments are passed as an ANSI string.
How does the compiler know to invoke wWinMain instead of the standard main function? What actually happens is that the Microsoft C runtime library (CRT) provides an implementation of main that calls either WinMain or wWinMain.
The CRT does some more work inside main. For example, it calls any static initializers before wWinMain. Although you can tell the linker to use a different entry-point function, you should use the default if you link to the CRT. Otherwise, the CRT initialization code is skipped, with unpredictable results such as global objects not being initialized correctly.
2. C++ 编译器在编译匿名名称空间时,会为这个名称空间生成一个唯一的名字,并附加上对应的 using 指令,以达到只允许在某个文件内访问这个名称空间内部变量的效果。

浙公网安备 33010602011771号