第一次VS2005运行Win32程序 的问题

在VS2005中建立WIN32程序的空项目.

#include <windows.h>

int WINAPI   WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPWSTR lpCmdLine,
  int nShowCmd
)
{
 MessageBox(NULL,"hELLO","HELLO",MB_OK);
 return 0;
}
出错了

正在编译...
Finish.cpp
./Finish.cpp(10) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [6]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
生成日志保存在“file://f:/Inside MFC/Finish/Finish/Release/BuildLog.htm”

Unicode的问题

右击项目--->属性---->常规 

在右边的项目默认值

  字符集    改为 未设置

重新编译

正在编译...
Finish.cpp
./Finish.cpp(9) : error C2731: 'WinMain' : function cannot be overloaded
        ./Finish.cpp(3) : see declaration of 'WinMain'

这下可难住我了,我明明就定义了一个,而且我是从MSDN直接拷的,怎么会说我重载了呢.

百度了,没这方面的资料.

头痛.百思不得其解,群里有人提示  LPWSTR lpCmdLine.多了个W.

果真如此.LPWSTR是支持宽字符的.

 修改,编译如下

#include <windows.h>

int WINAPI WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nShowCmd
)
{
 MessageBox(NULL,"hELLO","HELLO",MB_OK);
 return 0;
}

成功了,没想到就这么一个小小的细节.耗了我半个多小时.

后来只是想想原因,是自己拷贝MSDN上的东西时,没注意.

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值