Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ext/ffi_c/DynamicLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,16 @@ dl_open(const char* name, int flags)
static void
dl_error(char* buf, int size)
{
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
0, buf, size, NULL);
// Get the last error code
DWORD error = GetLastError();

// Get the associated message
LPSTR message = NULL;
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, error, 0, (LPSTR)&message, 0, NULL);

// Update the passed in buffer
snprintf(buf, size, "Failed with error %d: %s", error, message);
}
#endif

Expand Down