From 15d7148926e72249c282b65374b88c2a66bb711a Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 24 Jul 2011 07:00:54 +0000 Subject: [PATCH] forgot an add --- BizHawk.MultiClient/ExternalCoreSupport.cs | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 BizHawk.MultiClient/ExternalCoreSupport.cs diff --git a/BizHawk.MultiClient/ExternalCoreSupport.cs b/BizHawk.MultiClient/ExternalCoreSupport.cs new file mode 100644 index 0000000000..7b4113a3a6 --- /dev/null +++ b/BizHawk.MultiClient/ExternalCoreSupport.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; +using System.Linq; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Collections.Generic; + +using BizHawk; + +namespace BizHawk.MultiClient +{ + + /// + /// accesses a shared library using LoadLibrary and GetProcAddress + /// + public class Win32LibAccessor : ILibAccessor + { + public Win32LibAccessor(string dllPath) + { + mDllHandle = LoadLibrary(dllPath); + if (mDllHandle == IntPtr.Zero) return; + IsOpen = true; + } + + public bool IsOpen { get; private set; } + + IntPtr mDllHandle; + + IntPtr ILibAccessor.GetProcAddress(string name) + { + if (!IsOpen) throw new InvalidOperationException("dll was not opened, you can't get a symbol from it"); + IntPtr ret = GetProcAddress(mDllHandle, name); + if (ret == IntPtr.Zero) throw new InvalidOperationException("symbol name was not found in dll!"); + return ret; + } + + public void Dispose() + { + if (mDllHandle == IntPtr.Zero) + FreeLibrary(mDllHandle); + mDllHandle = IntPtr.Zero; + IsOpen = false; + } + + ~Win32LibAccessor() + { + Dispose(); + } + + [DllImport("kernel32.dll")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll")] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32.dll")] + public static extern bool FreeLibrary(IntPtr hModule); + } + +} \ No newline at end of file