编译错误 error C2731 Winmain

来源:互联网 发布:自己的淘宝信誉查询 编辑:程序博客网 时间:2024/05/22 06:33
  很多时候在我们读一些英文编程资料的时候,经常会遇到写Windows主入口函数的问题,英文一般会这样写:

// This is winmain, the main entry point for Windows applications
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )

不过照抄下来在VS2005或VS2008编译的时候总会说error C2731: “WinMain”: 无法重载函数。其实因为WinMain函数的原始定义中lpCmdLine的类型是char *,但在中文系统的环境下因为启用了Unicode支持,LPTSTR代表的是WCHAR *。所以上述函数我们就应该这样来写:

// This is winmain, the main entry point for Windows applications
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )

自然也就不会有问题了。

原创粉丝点击