CreateFileW GetLastError 返回 2

时间:2021-07-25 01:50:19

标签: c++ file registry

void * hFile = CreateFileW
(
    L"\\\\.\\OurFile",        // name of the write
    GENERIC_WRITE,          // open for writing
    0,                      // do not share
    NULL,                   // default security
    CREATE_NEW,             // create new file only
    FILE_ATTRIBUTE_NORMAL,  // normal file
    NULL
);

if (!hFile || hFile == INVALID_HANDLE_VALUE)
{
   std::cout << "hFile GetLastError(): 0x" << std::hex << GetLastError() << std::endl;
   std::getchar();
}

我上面的代码试图创建一个文件。但奇怪的是,GetLastError() 以某种方式返回 2?我检查了 Microsoft 的文档,如果文件不存在,则返回 2。但我正在尝试创建一个文件而不是打开现有的文件。如果有人有解决方案,请告诉我。谢谢大家的时间。

0 个答案:

没有答案
相关问题