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

Skip to content

Commit a17aeb8

Browse files
authored
Merge pull request #1026 from cfis/master
Windows - Update LoadLibrary Error Message to include Error Code
2 parents b1003b8 + 2bc282d commit a17aeb8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ext/ffi_c/DynamicLibrary.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,16 @@ dl_open(const char* name, int flags)
225225
static void
226226
dl_error(char* buf, int size)
227227
{
228-
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
229-
0, buf, size, NULL);
228+
// Get the last error code
229+
DWORD error = GetLastError();
230+
231+
// Get the associated message
232+
LPSTR message = NULL;
233+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
234+
NULL, error, 0, (LPSTR)&message, 0, NULL);
235+
236+
// Update the passed in buffer
237+
snprintf(buf, size, "Failed with error %d: %s", error, message);
230238
}
231239
#endif
232240

0 commit comments

Comments
 (0)