来自 MSDN (格式消息函数):
Windows 10:
LocalFree is not in the modern SDK, so it cannot be used to free the result buffer. Instead, use HeapFree (GetProcessHeap(), allocatedMessage). In this case, this is the same as calling LocalFree on memory.
我不知道如何使用 HeapFree,但我想在 Windows 7、Windows 8/8.1 和 Windows 10 中运行该应用程序,但我目前只使用 LocalFree,它正在运行。
这是我的代码:
VOID ShowErrorMsg(DWORD messageId)
{
DWORD flags=FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
DWORD languageID = LANG_USER_DEFAULT;
LPWSTR errorMsg;
DWORD size = 0;
FormatMessageW(flags, NULL, messageId, languageID, (LPTSTR)&errorMsg, size, NULL);
wprintf(L"\n%s", errorMsg);
LocalFree(errorMsg);
}
我的问题是,我是否应该使用像 IsWindows7SP1OrGreater
、IsWindows8Point1OrGreater
和 IsWindows10OrGreater
这样的函数,from Version Helper functions , 在调用 LocalFree
或 HeapFree
之前?
如果我必须调用HeapFree
,谁能给我一个如何使用它的例子吗?
谢谢!
最佳答案
这里的“Modern”是指 WinRT/Metro/Modern/Store 应用程序。 LocalFree
存在于每个版本的 Windows 上,并且可供所有 Windows 版本上的经典/桌面应用程序使用。
关于c - 在使用 Windows 7/8.1 和 Windows 10 的 FormatMessage 中的 LocalFree/HeapFree 之前,我是否应该查询操作系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106413/