summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2023-04-20 09:00:07 +0200
committerGitHub <noreply@github.com>2023-04-20 09:00:07 +0200
commita17aeb88c98a51ddfaff1f85e91612a105c088c5 (patch)
tree9309e8128b5ae98f74a553403addd3ed9d2fafcd
parentb1003b82599ff387598e612da1db9c513bed22b5 (diff)
parent2bc282d216ba3eae7a263eef90c9b11da6064457 (diff)
downloadffi-a17aeb88c98a51ddfaff1f85e91612a105c088c5.tar.gz
Merge pull request #1026 from cfis/master
Windows - Update LoadLibrary Error Message to include Error Code
-rw-r--r--ext/ffi_c/DynamicLibrary.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/ffi_c/DynamicLibrary.c b/ext/ffi_c/DynamicLibrary.c
index 9bfe86e..6c27ec6 100644
--- a/ext/ffi_c/DynamicLibrary.c
+++ b/ext/ffi_c/DynamicLibrary.c
@@ -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