gpt4 book ai didi

c++ - 如何在 VC++ 2010 中使用 GetLastError()

转载 作者:行者123 更新时间:2023-11-30 04:36:32 27 4
gpt4 key购买 nike

从 Java 到 C++ 的转换并不容易,所以请帮助我。

我想看看我是否在这段代码中遇到了 Access_Error 冲突:

BOOL didThisFail = FALSE;

if (CopyFile(L"MyApplication.exe", szPath, didThisFail))
cout << "File was copied" << endl;

最佳答案

if (CopyFileW(L"MyApplication.exe", szPath, didThisFail))
{
std::cout << "File was copied" << std::endl;
}
else if (GetLastError() == ERROR_ACCESS_DENIED)
{
std::cout << "Can't do that." << std::endl;
}
else
{
DWORD lastError = GetLastError();
//You have to cache the value of the last error here, because the call to
//operator<<(std::ostream&, const char *) may cause the last error to be set
//to something else.
std::cout << "General failure. GetLastError returned " << std::hex
<< lastError << ".";
}

关于c++ - 如何在 VC++ 2010 中使用 GetLastError(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4500516/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com