Browse Source
Reworked library loading so that the native DLL and its functions are now loaded dynamically using native LoadLibrary/GetProcAddress calls and can be freed again with FreeLibrary. This allows the library to be unloaded while in the Unity Editor, making iteration on native code easier, and it's a first step on the way to loading multiple Quake instances simultaneously.
console
Reworked library loading so that the native DLL and its functions are now loaded dynamically using native LoadLibrary/GetProcAddress calls and can be freed again with FreeLibrary. This allows the library to be unloaded while in the Unity Editor, making iteration on native code easier, and it's a first step on the way to loading multiple Quake instances simultaneously.
console
3 changed files with 106 additions and 12 deletions
-
30Assets/Scripts/SystemLibrary.cs
-
11Assets/Scripts/SystemLibrary.cs.meta
-
73Assets/Scripts/UniQuake.cs
@ -0,0 +1,30 @@ |
|||||
|
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
|
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: d583e6fe28a9299438ec95a379db0527 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue