1

When I executed the following code piece it fails with error code 317. How can solve the issue? We are using Unicode Character Set for the project

  char* pszMessgeBuffer = NULL;
  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM | 
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dwErrorId,
        0, // Default language
        (LPTSTR) &pszMessgeBuffer,
        0,
        NULL )
Maanu
  • 5,093
  • 11
  • 59
  • 82
  • Is semicolon missing at the function end ? – iammilind Jun 07 '11 at 11:34
  • @iammilind: The OP is able to compile, so I think no. – Yakov Galka Jun 07 '11 at 11:35
  • 2
    Error code 317 is `ERROR_MR_MID_NOT_FOUND`. So I would guess the `dwErrorId` is somehow wrong. The number must be a valid system message. – mkaes Jun 07 '11 at 11:40
  • @mkaes:The Call Failed when I gave dwErrorID as 10061. I got this value from GetLastError(). I am getting this error only in Windows CE – Maanu Jun 07 '11 at 11:55
  • Ok. So it must be a WinCE specific issue, because your code returns on my machine `No connection could be made because the target machine actively refused it`. I am not familiar with WinCE but maybe the error code 10061 is not in the system message table on CE. Check your winerror.h in the SDK. If the 10061 is not in there I assume that there is no system message for it. – mkaes Jun 07 '11 at 12:11
  • 1
    That's one evil cast, it can never work properly. It only stops the compiler from telling you that you did something wrong. Use FormatMessageA() or pass a wchar_t[]. – Hans Passant Jun 07 '11 at 13:09
  • 1
    Why are you using char* and then casting that to a wide (LPTSTR) string? That's really bad form and will not make the target a char*. It's not causing this specific error, but it's still bad form. Using it here indicates you're probably doing it elsewhere too. – ctacke Jun 07 '11 at 13:13

2 Answers2

6

Using the error code lookup tool from Visual Studio, 317 is described as

The system cannot find message text for message number 0x%1 in the message file for %2.

This means that a message description does not exist in the system for the previous error code. The MSDN documentation for FormatMessage with flag FORMAT_MESSAGE_FROM_SYSTEM states that:

Not all Windows Embedded CE–based devices will contain the system message-table resources. This is a selectable part of the Windows Embedded CE operating system and is often removed to conserve space.

Garett
  • 16,632
  • 5
  • 55
  • 63
0

I think error 317 is the result of using Win32 function LsaNtStatusToWinError(87), where winstatus 87 means 'The parameter is incorrect'