CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

一个刚学习VC学生提的问题!===>(在线等)

楼主houwei16(程序戴眼镜)2003-08-03 17:27:43 在 C/C++ / C语言 提问

WinMain函数是这样定义的  
  int   WINAPI   WinMain(HINSTANCE   hThisInst,HINSTANCE   hPrevInst,  
                                        LPSTR   lpszArgs,int   nWinMode)  
  {       .  
          .  
          .  
          .  
  }  
  我始终搞不懂,c++标准里面没有这样的定义方法,最多也是写成这样  
  extern   int   a(int   b,int   c)  
  为什么在WINDOWS编程里面会这样定义,是不是应该写成  
  WINAPI   int   WinMain(.........)  
  那么为什么WinMain前面为什么要加WINAPI,他是什么意思?  
  希望那位高手给小弟一个详细的解释,小弟不胜感激呀!!!!!!!!!  
  问题点数:100、回复次数:3Top

1 楼zhangyan_qd(doggyzone)回复于 2003-08-03 17:35:43 得分 20

#define   WINAPI  
  int   WINAPI   WinMain(....)  
  ...  
   
  没什么问题了吧?   WINAPI不是数据类型,只是一个编译指示。Top

2 楼houwei16(程序戴眼镜)回复于 2003-08-03 18:06:06 得分 0

不太懂,还请大哥给详细解释一下!  
  还有,这么说,我是不是可以在Turbo   C++3.0下这样写?  
  #define   WINAPI    
  void   main()  
  {  
          printf("Hello!!!\n");  
  }  
  我看不对吧!!!!!!  
  Top

3 楼plainsong(短歌)()回复于 2003-08-03 18:09:05 得分 80

WINAPI是个宏,一般定义为__stdcall,这是一个非标准关键字,是Windows   API的参数传递方式。  
   
  HINSTANCE和LPSTR則是类型定义。  
   
  上面的代码相当于  
  int   __stdcall   WinMain(HINSTANCE   hThisInst,   HINSTANCE   hPrevInst,  
                                        LPSTR   lpszArgs,int   nWinMode)  
   
  下面描述来自MSDN中关于__stdcall的解释:  
  __stdcall  
  Home   |     Overview   |     How   Do   I  
   
  Microsoft   Specific   —>  
   
  The   __stdcall   calling   convention   is   used   to   call   Win32   API   functions.   The   callee   cleans   the   stack,   so   the   compiler   makes   vararg   functions   __cdecl.   Functions   that   use   this   calling   convention   require   a   function   prototype.   The   following   list   shows   the   implementation   of   this   calling   convention.  
   
  Element   Implementation    
  Argument-passing   order   Right   to   left.    
  Argument-passing   convention   By   value,   unless   a   pointer   or   reference   type   is   passed.    
  Stack-maintenance   responsibility   Called   function   pops   its   own   arguments   from   the   stack.    
  Name-decoration   convention   An   underscore   (_)   is   prefixed   to   the   name.   The   name   is   followed   by   the   at   sign   (@)   followed   by   the   number   of   bytes   (in   decimal)   in   the   argument   list.   Therefore,   the   function   declared   as   int   func(   int   a,   double   b   )   is   decorated   as   follows:   _func@12    
  Case-translation   convention   None    
   
   
  The   /Gz   compiler   option   specifies   __stdcall   for   all   functions   not   explicitly   declared   with   a   different   calling   convention.    
   
  Functions   declared   using   the   __stdcall   modifier   return   values   the   same   way   as   functions   declared   using   __cdecl.    
   
  END   Microsoft   Specific  
   
  Example  
  In   the   following   example,   use   of   __stdcall   results   in   all   WINAPI   function   types   being   handled   as   a   standard   call:  
   
  //   Example   of   the   __stdcall   keyword  
  #define   WINAPI   __stdcall  
   
  Top

相关问题

  • 学习VC
  • 请教:学习VC++?
  • vc++如何学习
  • 怎样学习VC++?
  • 怎样学习vc++?!?!?!?!?!?!?!?!?!?!?
  • 怎样学习VC
  • 如何学习VC++
  • VC学习问题
  • 怎样学习vc
  • 关于学习VC++!

关键词

  • c++
  • winmain
  • winapi
  • convention
  • 定义
  • hinstance
  • stdcall
  • lpstr
  • 解释
  • argument

得分解答快速导航

  • 帖主:houwei16
  • zhangyan_qd
  • plainsong

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo