unicode下也可使用char吗,要不要都写成TCHAR*

sb3day 2010-12-24 03:10:45
unicode编码下也可使用char吗,要不要都写成TCHAR*

还有个问题哈:在项目代码里看到这一行:while(WaitForSingleObject(MMutex,INFINITE) != WAIT_OBJECT_0);
WaitForSingleObject会自动等待,while多余的吧????

我查了资料:WaitForSingleObject、Sleep、SetTimer等都是低精度计时,当指定时间小于10ms时,会自动按10ms计算。(这个10ms可能与系统版本有关,也可能受其它软件影响)
高精度定时可以用timeSetEvent或CreateWaitableTimer、SetWaitableTimer。


请问有必要写while吗?
...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2010-12-24
  • 打赏
  • 举报
回复
WaitForSingleObject

If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values.

Return code/value Description
WAIT_ABANDONED
0x00000080L
The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.

If the mutex was protecting persistent state information, you should check it for consistency.

WAIT_OBJECT_0
0x00000000L
The state of the specified object is signaled.

WAIT_TIMEOUT
0x00000102L
The time-out interval elapsed, and the object's state is nonsignaled.


If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF). To get extended error information, call GetLastError.
ouyh12345 2010-12-24
  • 打赏
  • 举报
回复
2、如果是互斥,可能会返回WAIT_ABANDONED
The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.

If the mutex was protecting persistent state information, you should check it for consistency.
bragi523 2010-12-24
  • 打赏
  • 举报
回复
用什么都可以,到时候转一下,有时候也是需要char*类型的

那个while主要是在WaitForSingleObject的第二个参数不等于INFINITE是使用
zhangyan_wt 2010-12-24
  • 打赏
  • 举报
回复
如果用到strXXX(比如strcpy)系列的函数都是要用char的,当然如果用unicode编程,这种函数可以用wcsXXX或者_tcsXXX代替。
建议都用t系列的,双编译,比较保险。
另外就是真的需要按字节分配内存的时候,BYTE(unsigned char)就不用转了
varding 2010-12-24
  • 打赏
  • 举报
回复
1、工程设置了unicode编码,windows api以字符串做参数的都需要unicode输入了,但是你自己的函数可以不限,char还是可以用的
2、个人觉得while是多余的,既然是无限等待了,这儿就没必要while了

15,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧