Project

General

Profile

Bug #9699 ยป dln_load.patch

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

View differences:

dln.c
1246 1246
#define translit_separator(str) (void)(str)
1247 1247
#endif
1248 1248

  
1249
#if defined _WIN32 && !defined __CYGWIN__
1250
static WCHAR *
1251
mbstr_to_wstr(UINT cp, const char *str)
1252
{
1253
    WCHAR *ptr;
1254
    int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0);
1255
    ptr = malloc(sizeof(WCHAR) * len);
1256
    if (!ptr)
1257
        return 0;
1258
    if (!MultiByteToWideChar(cp, 0, str, -1, ptr, len)) {
1259
        free(ptr);
1260
        ptr = 0;
1261
    }
1262
    return ptr;
1263
}
1264
#endif
1265

  
1249 1266
void*
1250 1267
dln_load(const char *file)
1251 1268
{
......
1256 1273

  
1257 1274
#if defined _WIN32 && !defined __CYGWIN__
1258 1275
    HINSTANCE handle;
1259
    char winfile[MAXPATHLEN];
1276
    WCHAR *winfile;
1260 1277
    char message[1024];
1261 1278
    void (*init_fct)();
1262 1279
    char *buf;
......
1266 1283
    /* Load the file as an object one */
1267 1284
    init_funcname(&buf, file);
1268 1285

  
1269
    strlcpy(winfile, file, sizeof(winfile));
1286
    handle = 0;
1287
    /* Convert the file path to wide char */
1288
    winfile = mbstr_to_wstr(CP_UTF8, file);
1289
    if (winfile) {
1290
        /* Load the library */
1291
        handle = LoadLibraryW(winfile);
1292
        free(winfile);
1293
    }
1270 1294

  
1271
    /* Load file */
1272
    if ((handle = LoadLibrary(winfile)) == NULL) {
1295
    /* Handle failure */
1296
    if (!handle) {
1273 1297
	error = dln_strerror();
1274 1298
	goto failed;
1275 1299
    }