gpt4 book ai didi

c++ - 我可以在函数的第一行启动 `GetLastError` 吗?

转载 作者:行者123 更新时间:2023-11-28 00:10:20 25 4
gpt4 key购买 nike

我知道 GetLastError 会在发生错误时立即调用。我写了函数:

void PrintErrorMsg() {
DWORD errCode = GetLastError();
LPTSTR msg = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errCode, 0, (LPTSTR)&msg, 0, NULL);
wcerr << msg << endl;
HeapFree(GetProcessHeap(), 0, msg);
}

现在我在我的代码中使用它:

LPCTSTR boundaryName = L"BushmanBoundary";
HANDLE hBoundary = CreateBoundaryDescriptor(boundaryName, 0);
if (NULL == hBoundary) {
PrintErrorMsg();
}

所以我在 PrintErrorMsg 函数的第一行代码中调用了 GetLastError。这样的 using 变体是否可以接受?

最佳答案

该代码没问题。在 CreateBoundaryDescriptor 返回和您对 GetLastError 的调用之间没有调用任何 Windows API 函数。

关于c++ - 我可以在函数的第一行启动 `GetLastError` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482618/

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