public void loadLibrary(String path, String dll_name, string resource_name, bool make_unique_dll_name) { lock (_sync_object) { DllData data = null; if (_loaded_dlls.TryGetValue(dll_name, out data)) { // Library has already been loaded if (data.lib_path != path) { throw new Exception(String.Format("Library {0} has already been loaded by different path {1}", dll_name, data.lib_path)); } return; } String subprefix = null; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: subprefix = (IntPtr.Size == 8) ? "Win/x64/" : "Win/x86/"; break; case PlatformID.Unix: if (isMac()) { subprefix = "Mac/10.7/"; } else { subprefix = (IntPtr.Size == 8) ? "Linux/x64/" : "Linux/x86/"; } break; default: throw new PlatformNotSupportedException(String.Format( "Unsupported platform: {0}", Environment.OSVersion.Platform ) ); } data = new DllData(); data.lib_path = path; data.file_name = _getPathToBinary(path, subprefix + dll_name, resource_name, Assembly.GetCallingAssembly(), make_unique_dll_name); data.file_name = data.file_name.Replace('/', '\\'); data.handle = LibraryLoader.LoadLibrary(data.file_name); if (data.handle == IntPtr.Zero) { throw new Exception("Cannot load library " + dll_name + " from the temporary file " + data.file_name.Replace('\\', '/') + ": " + LibraryLoader.GetLastError() ); } _loaded_dlls.Add(dll_name, data); _dll_handles.Add(data); } }
public void loadLibrary(String path, String dll_name, string resource_name, bool make_unique_dll_name) { lock (_sync_object) { DllData data = null; if (_loaded_dlls.TryGetValue(dll_name, out data)) { // Library has already been loaded if (data.lib_path != path) { throw new Exception(String.Format("Library {0} has already been loaded by different path {1}", dll_name, data.lib_path)); } return; } data = new DllData(); data.lib_path = path; data.file_name = _getPathToBinary(path, dll_name, resource_name, Assembly.GetCallingAssembly(), make_unique_dll_name); data.file_name = data.file_name.Replace('/', '\\'); data.handle = LibraryLoader.LoadLibrary(data.file_name); if (data.handle == IntPtr.Zero) { throw new Exception("Cannot load library " + dll_name + " from the temporary file " + data.file_name.Replace('\\', '/') + ": " + LibraryLoader.GetLastError() ); } _loaded_dlls.Add(dll_name, data); _dll_handles.Add(data); } }