尝试读取 EventLog 时 FormatMessage 收到错误 317
我对此有几乎类似的问题。 FormatMessage 失败,错误代码为 317
不同之处在于,作为答案这是由“FORMAT_MESSAGE_FROM_SYSTEM”
引起的,但当我删除它时,它又发生了。
我正在尝试从 Windows Server 2003 中的 EventLog
读取数据。但是当我尝试使用 FormatMessage
函数时,出现 317
错误。
有趣的是,相同的代码适用于 Windows Server 2008。我该如何解决这个问题,或者我可以使用什么来代替 FormatMessage
?
我的代码:
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
g_hResources, // handles DLL containing message table
MessageId,
0, // Default language
(LPWSTR) &pMessage,
0,
(va_list*)pArgs )
祝你有美好的一天..
I had nearly similar problem with this.
FormatMessage Fails with error code 317
The difference is it is said as an answer that this is caused by "FORMAT_MESSAGE_FROM_SYSTEM"
but when I remove it it happens again.
I am trying to read from EventLog
in Windows Server 2003. But when I try to use FormatMessage
function I get 317
error.
Interestingly same code works for Windows Server 2008. How can I fix this or what can I use instead of FormatMessage
?
My code:
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
g_hResources, // handles DLL containing message table
MessageId,
0, // Default language
(LPWSTR) &pMessage,
0,
(va_list*)pArgs )
Good day to you..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误 317 是“系统无法在 %2 的消息文件中查找消息号 0x%1 的消息文本。”。这意味着
MessageId
不是系统已知的错误号。您正在组合
FORMAT_MESSAGE_FROM_HMODULE
和FORMAT_MESSAGE_FROM_SYSTEM
,这是没有意义的。您想从哪里获取消息?您想从g_hResources
获取还是从系统错误消息表获取?从评论来看,您似乎想从g_hResources
获取它,在这种情况下,您应该删除FORMAT_MESSAGE_FROM_SYSTEM
。如果仍然收到错误 317,则意味着g_hResources
中不存在您传递的消息号。Error 317 is "The system cannot find message text for message number 0x%1 in the message file for %2.". That means the
MessageId
is not an error number known to the system.You are combining
FORMAT_MESSAGE_FROM_HMODULE
andFORMAT_MESSAGE_FROM_SYSTEM
, which doesn't make sense. Where do you want to get the message from? Do you want to get it fromg_hResources
or from the system error message table? From the comment, it sounds like you want to get it fromg_hResources
, in which case you should removeFORMAT_MESSAGE_FROM_SYSTEM
. If you still get error 317, then it means that the message number you passed doesn't exist ing_hResources
.