- FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL);
- fprintf (stderr, "%s\n", (char *)lpMsgBuf) ;
- //FIXME : it crashes
- // if (lpMsgBuf)
- // free (lpMsgBuf);
+
+ if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL))
+ fprintf (stderr, "%s\n", (char *)lpMsgBuf);
+ else
+ fprintf (stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError());