0

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

Community
  • 1
  • 1
abbas sebastian
  • 105
  • 5
  • 14

1 Answers1

2

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.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 1
    Using `FORMAT_MESSAGE_FROM_HMODULE` and `FORMAT_MESSAGE_FROM_SYSTEM` together is explicitly [documented in the MSDN Library](http://msdn.microsoft.com/en-us/library/windows/desktop/ms679351.aspx#format_message_from_system): in this case "the function searches the system message table if the message is not found in the module specified by _lpSource_". – Brian Nixon Dec 18 '11 at 18:08
  • I stand corrected. But it's strange that you don't know where the message is going to be found. You should know. Messages in the event log typically do not come from the system anyway. They are event-specific and come from the event's message provider. – Raymond Chen Dec 18 '11 at 18:38