unicode编码下也可使用char吗,要不要都写成TCHAR*还有个问题哈:在项目代码里看到这一行:while(WaitForSingleObject(MMutex,INFINITE) != WAIT_OBJECT_0);
WaitForSingleObject会自动等待,while多余的吧????我查了资料:WaitForSingleObject、Sleep、SetTimer等都是低精度计时,当指定时间小于10ms时,会自动按10ms计算。(这个10ms可能与系统版本有关,也可能受其它软件影响)
高精度定时可以用timeSetEvent或CreateWaitableTimer、SetWaitableTimer。 
请问有必要写while吗?

解决方案 »

  1.   

    1、工程设置了unicode编码,windows api以字符串做参数的都需要unicode输入了,但是你自己的函数可以不限,char还是可以用的
    2、个人觉得while是多余的,既然是无限等待了,这儿就没必要while了
      

  2.   

    如果用到strXXX(比如strcpy)系列的函数都是要用char的,当然如果用unicode编程,这种函数可以用wcsXXX或者_tcsXXX代替。
    建议都用t系列的,双编译,比较保险。
    另外就是真的需要按字节分配内存的时候,BYTE(unsigned char)就不用转了
      

  3.   

    用什么都可以,到时候转一下,有时候也是需要char*类型的那个while主要是在WaitForSingleObject的第二个参数不等于INFINITE是使用
      

  4.   

    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.
      

  5.   

    WaitForSingleObjectIf 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.