c - 在使用 Windows 7/8.1 和 Windows 10 的 FormatMessage 中的 LocalFree/HeapFree 之前,我是否应该查询操作系统?

标签 c windows winapi

来自 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);

}

我的问题是,我是否应该使用像 IsWindows7SP1OrGreaterIsWindows8Point1OrGreaterIsWindows10OrGreater 这样的函数,from Version Helper functions , 在调用 LocalFreeHeapFree 之前?

如果我必须调用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/

相关文章:

c - C 中的列表 : can't add new elements

windows - 使用 API 从我的应用程序监视 RAS 拨号连接

windows - 如何以编程方式检索区域和语言设置中显示的 "Location"?

c# - 查找不同 Windows 用户的 LocalAppData

c - c中的初始化是如何工作的?

c - 回文检查器

c - 为什么我们可以读取这个分配的指针中的任何字符而不写入它?

c++ - 从 Windows 上的 C++ 或 Python 的串口读取

linux - 适用于 Windows 的 XDG Basedir 目录

c++ - 仅允许垂直窗口调整大小的最简单方法是什么?