VC中易犯的错误
来源:互联网 发布:淘宝扣子 编辑:程序博客网 时间:2024/06/05 11:06
在这里面总结一下VC中易常犯的错误.
一/前两天过一个串口的通迅程序,有如下一段代码:
HANDLE hCom=CreateFile(......);(构造函数里面将hCom=NULL)
if(hCom)
{
//如果hCom有值,则说明创建成功
}
else
{
//没成功
}
看上去好像没什么问题,其实错的很彻底.
Windows via c/c++中有这样一段话:
Note
一/前两天过一个串口的通迅程序,有如下一段代码:
HANDLE hCom=CreateFile(......);(构造函数里面将hCom=NULL)
if(hCom)
{
//如果hCom有值,则说明创建成功
}
else
{
//没成功
}
看上去好像没什么问题,其实错的很彻底.
Windows via c/c++中有这样一段话:
If CreateFile succeeds in creating or opening a file or device, the handle of the file or device is returned. If CreateFile fails, INVALID_HANDLE_VALUE is returned.
Note
Most Windows functions that return a handle return NULL when the function fails. However, CreateFile returns INVALID_HANDLE_VALUE (defined as –1) instead. I have often seen code like this, which is incorrect:
HANDLE hFile = CreateFile(...);
if (hFile == NULL) {
// We'll never get in here
} else {
// File might or might not be created OK
}
Here's the correct way to check for an invalid file handle:
HANDLE hFile = CreateFile(...);
if (hFile == INVALID_HANDLE_VALUE) {
// File not created
} else {
// File created OK
}
- VC中易犯的错误
- VC++的LNK2005错误
- VC++的错误!
- VC++的LNK2005错误
- VC 新手的错误!
- vc++的一些错误
- VC的错误处理
- VC++的链接错误LNK2005
- VC++的链接错误LNK2005
- VC++的链接错误LNK2005
- VC++的链接错误LNK2005
- VC++的链接错误LINK2001
- VC++的链接错误LNK2005
- VC++的链接错误LNK2005
- VC++的链接错误LNK2001
- VC常见错误的解决
- VC++的链接错误LNK2005
- VC++的链接错误LNK2005
- Java Reflection 之 Method
- 程序设计经验总结
- gef之一----command模式
- (转贴)什么是socket
- Event和全局类
- VC中易犯的错误
- install linux as 5 in dell poweredge 2950
- ubuntu 下的boot 目录
- about seo
- IIS与Apache共用80端口方法
- Linux下mysql整个数据库的备份和还原
- 软件测试方法论----黑盒测试篇(开发观点看测试)
- Google Mountain View 总部园区超清晰卫星照片
- 给FileTabs添加双击关闭的功能