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_ */

 

后面也附有相关说明:

 /***

*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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值