加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

winapi – 如何使用FormatMessage c获取仅英文消息

发布时间:2020-12-16 03:45:32 所属栏目:百科 来源:网络整理
导读:我正在尝试使用格式消息来获取仅英文值 MSDN指定以下内容 DWORD WINAPI FormatMessage( _In_ DWORD dwFlags,_In_opt_ LPCVOID lpSource,_In_ DWORD dwMessageId,_In_ DWORD dwLanguageId,_Out_ LPTSTR lpBuffer,_In_ DWORD nSize,_In_opt_ va_list *Argument
我正在尝试使用格式消息来获取仅英文值

MSDN指定以下内容

DWORD WINAPI FormatMessage(
  _In_      DWORD dwFlags,_In_opt_  LPCVOID lpSource,_In_      DWORD dwMessageId,_In_      DWORD dwLanguageId,_Out_     LPTSTR lpBuffer,_In_      DWORD nSize,_In_opt_  va_list *Arguments
);

对于dwLanguageId参数,

The language identifier for the requested message. This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.

If you pass a specific LANGID in this parameter,FormatMessage will return a message for that LANGID only. If the function cannot find a message for that LANGID,it sets Last-Error to ERROR_RESOURCE_LANG_NOT_FOUND. If you pass in zero,FormatMessage looks for a message for LANGIDs in the following order:

  1. Language neutral
  2. Thread LANGID,based on the thread’s locale value
  3. User default LANGID,based on the user’s default locale value
  4. System default LANGID,based on the system default locale value
  5. US English

If FormatMessage does not locate a message for any of the preceding LANGIDs,it returns any language message string that is present. If that fails,it returns ERROR_RESOURCE_LANG_NOT_FOUND.

这是否意味着,如果传递值为5,它将以英语返回消息?

你能澄清一下吗?

解决方法

文档中的数字5表示,在尝试将零传递为参数值之后,美国英语是FormatMessage尝试使用的第五种语言,在尝试并失败前四个选项之后.这与传递该函数参数的值5无关.

要请求英文消息,请传入美国英语的LANGID值,您可以使用MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US)获取该值. FormatMessage文档链接到documentation on language identifiers,后者又链接到language identifier constants and strings页面.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读