abbas sebastian
abbas sebastian

Reputation: 105

FormatMessage gets Error 317 while trying to read EventLog

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..

Upvotes: 0

Views: 1443

Answers (1)

Raymond Chen
Raymond Chen

Reputation: 45173

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 and FORMAT_MESSAGE_FROM_SYSTEM, which doesn't make sense. Where do you want to get the message from? Do you want to get it from g_hResources or from the system error message table? From the comment, it sounds like you want to get it from g_hResources, in which case you should remove FORMAT_MESSAGE_FROM_SYSTEM. If you still get error 317, then it means that the message number you passed doesn't exist in g_hResources.

Upvotes: 2

Related Questions