changeset 513:4b619c5871ee

Use VAMP_PATH_32 environment variable instead of VAMP_PATH, when running in a 32-bit process within 64-bit Windows (WoW64)
author Chris Cannam
date Mon, 11 Jun 2018 11:31:47 +0100
parents 54277cb679ff
children da86fb0bccb3
files src/vamp-hostsdk/Files.cpp src/vamp-hostsdk/Files.h src/vamp-hostsdk/PluginHostAdapter.cpp
diffstat 3 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/vamp-hostsdk/Files.cpp	Fri Jun 08 11:25:19 2018 +0100
+++ b/src/vamp-hostsdk/Files.cpp	Mon Jun 11 11:31:47 2018 +0100
@@ -324,6 +324,48 @@
 }
 
 bool
+Files::isNonNative32Bit()
+{
+    // Return true if we are running on a system for which we should
+    // use the VAMP_PATH_32 variable instead of VAMP_PATH. This will
+    // be the case if we are a 32-bit executable but the OS is
+    // natively 64-bit.
+    //
+    // This currently works only on Windows; other operating systems
+    // will use VAMP_PATH always.
+    
+    if (sizeof(void *) == 8) {
+        return false;
+    }
+
+#ifdef _WIN32
+    BOOL wow64 = FALSE;
+    BOOL (WINAPI *fnIsWow64Process)(HANDLE, PBOOL) =
+        (BOOL (WINAPI *)(HANDLE, PBOOL)) GetProcAddress
+        (GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
+    if (fnIsWow64Process) {
+        if (fnIsWow64Process(GetCurrentProcess(), &wow64)) {
+            if (wow64) {
+                return true;
+            } else {
+                return false;
+            }
+        } else {
+            cerr << "Vamp::HostExt: Unable to query process architecture"
+                 << endl;
+            return false;
+        }
+    } else {
+        cerr << "Vamp::HostExt: Unable to query process architecture: "
+             << "Function not available" << endl;
+        return false;
+    }
+#endif
+
+    return false;
+}
+
+bool
 Files::getEnvUtf8(std::string variable, std::string &value)
 {
     value = "";
--- a/src/vamp-hostsdk/Files.h	Fri Jun 08 11:25:19 2018 +0100
+++ b/src/vamp-hostsdk/Files.h	Mon Jun 11 11:31:47 2018 +0100
@@ -63,6 +63,7 @@
     static std::string splicePath(std::string a, std::string b);
     static std::vector<std::string> listFiles(std::string dir, std::string ext);
 
+    static bool isNonNative32Bit();
     static bool getEnvUtf8(std::string variable, std::string &value);
 };
 
--- a/src/vamp-hostsdk/PluginHostAdapter.cpp	Fri Jun 08 11:25:19 2018 +0100
+++ b/src/vamp-hostsdk/PluginHostAdapter.cpp	Mon Jun 11 11:31:47 2018 +0100
@@ -72,7 +72,11 @@
     std::vector<std::string> path;
     std::string envPath;
 
-    (void)Files::getEnvUtf8("VAMP_PATH", envPath);
+    if (Files::isNonNative32Bit()) {
+        (void)Files::getEnvUtf8("VAMP_PATH_32", envPath);
+    } else {
+        (void)Files::getEnvUtf8("VAMP_PATH", envPath);
+    }
 
 #ifdef _WIN32
 #define PATH_SEPARATOR ';'