Project

General

Profile

Bug #9699 » dln_load.patch

BugraB (Bugra Barin), 04/03/2014 08:41 PM

View differences:

dln.c
#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)
{
......
#if defined _WIN32 && !defined __CYGWIN__
HINSTANCE handle;
char winfile[MAXPATHLEN];
WCHAR *winfile;
char message[1024];
void (*init_fct)();
char *buf;
......
/* 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;
}
(2-2/2)