Win32下不同类型项目编译错误原因及解析
今天看了一段Win32下API的代码,复制到已有的一个Win32项目中想查看结果,但是编译时候总出现如下错误:
查询__tmainCRTStartup时候发现这个是控制台的程序入口,而复制的代码使用的入口是_tWinMain,看来原因可能在这里,于是寻找项目属性,发现的确有设置项目类型的选项:
在这里将项目类型调整后编译正常。
以前没有注意到两种程序在vs中入口的区别,在网上顺藤摸瓜查了下,这两种程序在程序初始化的C语言库时已经同,属于NT内核的不同策略,具体加载的代码可以在
安装目录\VC\crt\src\crt0.c下找到,在这里面查到了加载时的源码段与相关注释:
#ifdef _WINMAIN_
int __app_type = _GUI_APP;
#else /* _WINMAIN_ */
int __app_type = _CONSOLE_APP;
#endif /* _WINMAIN_ */
#else /* _WINMAIN_ */
int __app_type = _CONSOLE_APP;
#endif /* _WINMAIN_ */
后面也附有相关说明:
/***
*mainCRTStartup(void)
*wmainCRTStartup(void)
*WinMainCRTStartup(void)
*wWinMainCRTStartup(void)
*
*Purpose:
* These routines do the C runtime initialization, call the appropriate
* user entry function, and handle termination cleanup. For a managed
* app, they then return the exit code back to the calling routine, which
* is the managed startup code. For an unmanaged app, they call exit and
* never return.
*
* Function: User entry called:
* mainCRTStartup main
* wmainCRTStartup wmain
* WinMainCRTStartup WinMain
* wWinMainCRTStartup wWinMain
*
*Entry:
*
*Exit:
* Managed app: return value from main() et al, or the exception code if
* execution was terminated by the __except guarding the call
* to main().
* Unmanaged app: never return.
*
*******************************************************************************/
看来微软的文档注释不是一般的强大,这里把这样这个模块的功能都介绍的差不多了。有时间在仔细看下NT的加载逻辑
转载于:https://www.cnblogs.com/shenyubao/archive/2011/07/12/2103944.html