diff --git a/dln.c b/dln.c index 1f93950..654a982 100644 --- a/dln.c +++ b/dln.c @@ -1246,6 +1246,23 @@ rb_w32_check_imported(HMODULE ext, HMODULE mine) #define translit_separator(str) (void)(str) #endif +#if defined _WIN32 && !defined __CYGWIN__ +static WCHAR * +mbstr_to_wstr(UINT cp, const char *str) +{ + WCHAR *ptr; + int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0); + ptr = malloc(sizeof(WCHAR) * len); + if (!ptr) + return 0; + if (!MultiByteToWideChar(cp, 0, str, -1, ptr, len)) { + free(ptr); + ptr = 0; + } + return ptr; +} +#endif + void* dln_load(const char *file) { @@ -1256,7 +1273,7 @@ dln_load(const char *file) #if defined _WIN32 && !defined __CYGWIN__ HINSTANCE handle; - char winfile[MAXPATHLEN]; + WCHAR *winfile; char message[1024]; void (*init_fct)(); char *buf; @@ -1266,10 +1283,17 @@ dln_load(const char *file) /* Load the file as an object one */ init_funcname(&buf, file); - strlcpy(winfile, file, sizeof(winfile)); + handle = 0; + /* Convert the file path to wide char */ + winfile = mbstr_to_wstr(CP_UTF8, file); + if (winfile) { + /* Load the library */ + handle = LoadLibraryW(winfile); + free(winfile); + } - /* Load file */ - if ((handle = LoadLibrary(winfile)) == NULL) { + /* Handle failure */ + if (!handle) { error = dln_strerror(); goto failed; }