using System; using System.IO; using System.Runtime.InteropServices; public static class SystemLibrary { #if UNITY_STANDALONE_WIN [DllImport("kernel32", EntryPoint = "LoadLibrary", SetLastError = true, CharSet = CharSet.Unicode)] private static extern IntPtr LoadLibraryNative(string lpFileName); [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetDllDirectory(string lpPathName); public static IntPtr LoadLibrary(string lpFileName) { string lpPathName = Path.GetDirectoryName(lpFileName); lpFileName = Path.GetFileName(lpFileName); SetDllDirectory(lpPathName.Replace('/', '\\')); return LoadLibraryNative(lpFileName); } [DllImport("kernel32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FreeLibrary(IntPtr hModule); [DllImport("kernel32")] public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); #endif }