下面是一个最简单的Windows应用程序:
#include <windows.h>
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
MessageBox(0,"该吃饭啦!", "温馨提示:", 0);
return 0;
}
结果为:
有两点值得特别注意:
1. 不要在Win32 Console Application中运行这个程序,否则会出错,请在Win32 Application中运行。否则,程序出现错误,错误提示为:
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
2. 如果自己写代码,很多东西可以直接从MSDN中复制,但要注意,如果WinMain函数中的参数变化了,那么就是WinMain的重载了,显然错误,错误代码为:(哦,这里强调一下,我用的是VC++6.0, 但MSDN是VS2008对应的版本,和VC++6.0对应的MSDN版本会有所不同,难怪有WinMain重载这个问题,建议用配套的MSDN版本)
#include <windows.h>
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, // 错误:应该是LPSTR
int nShowCmd
)
{
MessageBox(0,"该吃饭啦!", "温馨提示:", 0);
return 0;
}
错误提示为:error C2731: 'WinMain' : function cannot be overloaded