diff src/vamp-hostsdk/PluginLoader.cpp @ 284:1ed95908a397

* Win32 build fixes for UNICODE. Not yet tested
author cannam
date Mon, 15 Jun 2009 14:30:05 +0000
parents 4454843ff384
children c97e70ed5abc
line wrap: on
line diff
--- a/src/vamp-hostsdk/PluginLoader.cpp	Thu Apr 23 08:59:24 2009 +0000
+++ b/src/vamp-hostsdk/PluginLoader.cpp	Mon Jun 15 14:30:05 2009 +0000
@@ -513,7 +513,21 @@
 {
     void *handle = 0;
 #ifdef _WIN32
+#ifdef UNICODE
+    int len = path.length(); // cannot be more wchars than length in bytes of utf8 string
+    wchar_t *buffer = new wchar_t[len];
+    int rv = MultiByteToWideChar(CP_UTF8, 0, path.c_str(), len, buffer, len);
+    if (rv <= 0) {
+        cerr << "Vamp::HostExt::PluginLoader: Unable to convert library path \""
+             << path << "\" to wide characters " << endl;
+        delete[] buffer;
+        return handle;
+    }
+    handle = LoadLibrary(buffer);
+    delete[] buffer;
+#else
     handle = LoadLibrary(path.c_str());
+#endif
     if (!handle) {
         cerr << "Vamp::HostExt::PluginLoader: Unable to load library \""
              << path << "\"" << endl;
@@ -564,8 +578,41 @@
     vector<string> files;
 
 #ifdef _WIN32
+    string expression = dir + "\\*." + extension;
+#ifdef UNICODE
+    int len = expression.length(); // cannot be more wchars than length in bytes of utf8 string
+    wchar_t *buffer = new wchar_t[len];
+    int rv = MultiByteToWideChar(CP_UTF8, 0, expression.c_str(), len, buffer, len);
+    if (rv <= 0) {
+        cerr << "Vamp::HostExt::PluginLoader: Unable to convert wildcard path \""
+             << expression << "\" to wide characters" << endl;
+        delete[] buffer;
+        return files;
+    }
+    WIN32_FIND_DATA data;
+    HANDLE fh = FindFirstFile(buffer, &data);
+    if (fh == INVALID_HANDLE_VALUE) {
+        delete[] buffer;
+        return files;
+    }
 
-    string expression = dir + "\\*." + extension;
+    bool ok = true;
+    while (ok) {
+        wchar_t *fn = data.cFileName;
+        int wlen = wcslen(fn);
+        int maxlen = wlen * 6;
+        char *conv = new char[maxlen];
+        int rv = WideCharToMultiByte(CP_UTF8, 0, fn, wlen, conv, maxlen, 0, 0);
+        if (rv > 0) {
+            files.push_back(conv);
+        }
+        delete[] conv;
+        ok = FindNextFile(fh, &data);
+    }
+
+    FindClose(fh);
+    delete[] buffer;
+#else
     WIN32_FIND_DATA data;
     HANDLE fh = FindFirstFile(expression.c_str(), &data);
     if (fh == INVALID_HANDLE_VALUE) return files;
@@ -577,7 +624,7 @@
     }
 
     FindClose(fh);
-
+#endif
 #else
 
     size_t extlen = extension.length();