#region MIT license // // MIT license // // Copyright (c) 2013 Corey Murtagh // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #endregion using System; using System.Diagnostics; using System.Reflection; using System.Runtime.InteropServices; using System.Security; namespace NAudio.Lame { /* internal static class Loader { internal static bool Initialized = false; internal static string LoadedName; /// /// / /// /// /// [DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)] public extern static IntPtr LoadLibrary(string libraryName); [DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)] public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName); private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process); public static bool IsOS64Bit() { if (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor())) { return true; } else { return false; } } private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate() { IntPtr handle = LoadLibrary("kernel32"); if (handle != IntPtr.Zero) { IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process"); if (fnPtr != IntPtr.Zero) { return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate)); } } return null; } private static bool Is32BitProcessOn64BitProcessor() { IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate(); if (fnDelegate == null) { return false; } bool isWow64; bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64); if (retVal == false) { return false; } return isWow64; } //// private static Assembly LoadLameWrapper(object sender, ResolveEventArgs args) { //Console.WriteLine("LoadLameWrapper(): {0}", args.Name); var asmName = new AssemblyName(args.Name).Name + ".dll"; var srcAssembly = typeof(LameMP3FileWriter).Assembly; // Search resources for requested assembly byte[] src = null; foreach (string nxt in srcAssembly.GetManifestResourceNames()) { int p1 = nxt.IndexOf(IsOS64Bit() ? "x64" : "x86"); int p2 = nxt.IndexOf(asmName); if (p1 < 0 || p2 < 0 || p1 >= p2) continue; LoadedName = nxt; // Load resource into byte array using (var strm = srcAssembly.GetManifestResourceStream(nxt)) { src = new byte[strm.Length]; strm.Read(src, 0, (int)strm.Length); break; } } if (src == null) return null; // Load assembly from byte array //Console.WriteLine("Loaded {0} bytes from resource", src.Length); try { var res = Assembly.Load(src, null, System.Security.Policy.Evidence.Equals() SecurityContextSource.CurrentAppDomain); return res; } catch //(Exception e) { //Console.WriteLine("LoadLameWrapper: Failed to create assembly from buffer."); //Console.WriteLine("Exception:"); //Console.WriteLine("{0}", e.Message); throw; } } public static void Init() { if (!Initialized) { // Register assembly resolver AppDomain.CurrentDomain.AssemblyResolve += LoadLameWrapper; Initialized = true; } } } */ }