一个刚学习VC学生提的问题!===>(在线等)
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




