举例: hMutex = CreateMutex(NULL, FALSE,"screen");

 报错 error C2664:“CreateMutexW”: 不能将参数 3 从“const char [7]”转换为“LPCWSTR”

与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换;

解决:Ascii 环境调用CreateMutexA,unicode环境调用CreateMutexW

此例报错原因即是 使用的是unicode环境,函数自动调用的是CreateMutexW宽字符函数,所以参数LPCTSTR 是LPCWSTR类型的,加_T(),TEXT(),或L(字符)即可  hMutex = CreateMutex(NULL, FALSE,_T("screen"));或  hMutex = CreateMutex(NULL, FALSE,L"screen"); 或 hMutex = CreateMutex(NULL, FALSE,TEXT("screen"));

相关文章:

  • 2021-07-28
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2021-11-29
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2021-10-11
  • 2021-08-18
  • 2021-12-22
  • 2021-10-16
相关资源
相似解决方案