Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // error.h
- #ifndef __ERROR_H_
- #define __ERROR_H_
- void GetLastErrorAsString(LPTSTR msg);
- #endif
- // error.c
- #include "error.h"
- void GetLastErrorAsString(LPTSTR msg)
- {
- //Get the error message, if any.
- DWORD errorMessageID = GetLastError();
- if (errorMessageID == 0)
- return NULL; //No error message has been recorded
- LPSTR messageBuffer = NULL;
- size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, errorMessageID, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&messageBuffer, 0, NULL);
- lstrcpy(msg, messageBuffer);
- LocalFree(messageBuffer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement