//========================================================================== /// <summary> /// Frees the provided library. /// </summary> /// <param name="library"> /// The library to free. /// </param> /// <returns> /// The number how ofter the library is still referenced; will be <c>0</c> /// in case the library is no longer referenced and has been disposed. /// </returns> public static uint Free(LibVLCLibrary library) { if (library == null) { throw new ArgumentNullException("library"); } lock (m_LibraryHandles) { LibraryHandle library_handle; if (m_LibraryHandles.TryGetValue(library.Directory, out library_handle)) { if (library_handle.Library == library) { if (--library_handle.ReferenceCounter == 0) { library_handle.Library.Dispose(); m_LibraryHandles.Remove(library.Directory); } if (library_handle == m_DefaultLibraryHandle) { m_DefaultLibraryHandle = null; } return(library_handle.ReferenceCounter); } } } throw new ArgumentException("The provided library has not been loaded using the Load method!", "library"); }
public PlatformBinding() { string libraryName = null; string arch = (Is64Bit) ? "x64" : "x86"; PlatformOS os = Aws.Crt.Platform.GetRuntimePlatformOS(); switch (os) { case PlatformOS.WINDOWS: libraryName = $"aws-crt-dotnet-{arch}.dll"; break; case PlatformOS.UNIX: libraryName = $"libaws-crt-dotnet-{arch}.so"; break; case PlatformOS.MAC: libraryName = $"libaws-crt-dotnet-{arch}.dylib"; break; } try { libraryPath = ExtractLibrary(libraryName); // Work around virus scanners munching on a newly found DLL int tries = 0; do { crt = CRT.Loader.LoadLibrary(libraryPath); if (crt.IsInvalid) { Thread.Sleep(10); } } while (crt.IsInvalid && tries++ < 100); if (crt.IsInvalid) { string error = CRT.Loader.GetLastError(); throw new InvalidOperationException($"Unable to load {libraryPath}: error={error}"); } } catch (Exception ex) { throw new InvalidOperationException($"Unable to load {libraryPath}, exception occurred", ex); } Init(); }
//Creates new instance of ejdb. Don't know what' is it, but it looks it should be done before opening database public unsafe DatabaseFunctions(LibraryHandle handle) { NewInstance = handle.GetUnmanagedDelegate <NewInstanceDelegate>(); DeleteInstance = handle.GetUnmanagedDelegate <DeleteInstanceDelegate>(); OpenDatabase = handle.GetUnmanagedDelegate <OpenDatabaseDelegate>(); CloseDatabase = handle.GetUnmanagedDelegate <CloseDatabaseDelegate>(); IsOpen = handle.GetUnmanagedDelegate <IsOpenDelegate>(); GetErrorCode = handle.GetUnmanagedDelegate <GetErrorCodeDelegate>(); GetMetadata = handle.GetUnmanagedDelegate <GetMetaDelegate>(); Command = handle.GetUnmanagedDelegate <CommandDelegate>(); Sync = handle.GetUnmanagedDelegate <SyncDelegate>(); }
public HotReload(string path) { var randNum = Random.Range(100000, 999999); _tempFile = path + ".tmp." + randNum + ".dll"; File.Copy(path, _tempFile); var h = LoadLibrary(_tempFile); if (h.IsInvalid) { throw new Exception($"failed to load DLL"); } _handle = h; }
public PlatformBinding() { string libraryName = null; string arch = (Is64Bit) ? "x64" : "x86"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { libraryName = $"aws-crt-dotnet-{arch}.dll"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libraryName = $"libaws-crt-dotnet-{arch}.so"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libraryName = $"libaws-crt-dotnet-{arch}.dylib"; } try { libraryPath = ExtractLibrary(libraryName); // Work around virus scanners munching on a newly found DLL int tries = 0; do { crt = CRT.Loader.LoadLibrary(libraryPath); if (crt.IsInvalid) { Thread.Sleep(10); } } while (crt.IsInvalid && tries++ < 100); if (crt.IsInvalid) { string error = CRT.Loader.GetLastError(); throw new InvalidOperationException($"Unable to load {libraryPath}: error={error}"); } } catch (Exception ex) { throw new InvalidOperationException($"Unable to load {libraryPath}, exception occurred", ex); } Init(); }
public unsafe QueryFunctions(LibraryHandle handle) { Create = handle.GetUnmanagedDelegate <CreateQueryDelegate>(); Delete = handle.GetUnmanagedDelegate <DeleteQueryDelegate>(); Execute = handle.GetUnmanagedDelegate <ExecuteQueryDelegate>(); DeleteCursor = handle.GetUnmanagedDelegate <DeleteCursorDelegate>(); SetHints = handle.GetUnmanagedDelegate <SetHintsDelegate>(); AddOr = handle.GetUnmanagedDelegate <AddOrDelegate>(); CursorResult = handle.GetUnmanagedDelegate <CursorResultDelegate>(); NewBuffer = handle.GetUnmanagedDelegate <QueryFunctions.NewBufferDelegate>(); DeleteBuffer = handle.GetUnmanagedDelegate <QueryFunctions.DeleteBufferDelegate>(); BufferSize = handle.GetUnmanagedDelegate <GetSizeDelegate>(); BufferToString = handle.GetUnmanagedDelegate <ToStringDelegate>(); }
public unsafe CollectionFunctions(LibraryHandle handle) { CreateCollection = handle.GetUnmanagedDelegate <CreateCollectionDelegate>(); GetCollection = handle.GetUnmanagedDelegate <GetCollectionDelegate>(); Remove = handle.GetUnmanagedDelegate <RemoveCollectionDelegate>(); BeginTransaction = handle.GetUnmanagedDelegate <BeginTransactionDelegate>(); CommitTransaction = handle.GetUnmanagedDelegate <CommitTransactionDelegate>(); RollbackTransaction = handle.GetUnmanagedDelegate <RollbackTransactionDelegate>(); TransactionStatus = handle.GetUnmanagedDelegate <TransactionStatusDelegate>(); SyncCollection = handle.GetUnmanagedDelegate <SyncDelegate>(); SaveBson = handle.GetUnmanagedDelegate <SaveBsonDelegate>(); LoadBson = handle.GetUnmanagedDelegate <LoadBsonDelegate>(); DeleteBson = handle.GetUnmanagedDelegate <DeleteBsonDelegate>(); SetIndex = handle.GetUnmanagedDelegate <SetIndexDelegate>(); }
private unsafe Library(LibraryHandle libraryHandle) { LibraryHandle = libraryHandle; Functions = new Functions(libraryHandle); _getErrorMessage = LibraryHandle.GetUnmanagedDelegate <GetErrorMessage>(); _freeBson = libraryHandle.GetUnmanagedDelegate <FreeBsonDelegate>(); GetBsonData = libraryHandle.GetUnmanagedDelegate <BsonToStringDelegate>(); //_jsonToBson = libraryHandle.GetUnmanagedDelegate<JsonToBsonDelegate>(); var getVersion = LibraryHandle.GetUnmanagedDelegate <GetVersion>(); var version = getVersion(LibraryHandle); if (version == IntPtr.Zero.ToPointer()) { throw new Exception("Unable to get ejdb library version"); } _version = new string(version); //UnixMarshal.PtrToString(vres, Encoding.UTF8); _hexVersion = Convert.ToInt64("0x" + Version.Replace(".", ""), 16); }
public Functions(LibraryHandle handle) { Database = new DatabaseFunctions(handle); Collection = new CollectionFunctions(handle); Query = new QueryFunctions(handle); }
//========================================================================== private static LibraryHandle GetOrLoadLibrary(string libVLCDirectory) { LibraryHandle library_handle = null; lock (m_LibraryHandles) { if (libVLCDirectory != null) { if (!m_LibraryHandles.TryGetValue(libVLCDirectory, out library_handle)) { m_LibraryHandles.Add(libVLCDirectory, library_handle = new LibraryHandle(libVLCDirectory)); } ++library_handle.ReferenceCounter; return(library_handle); } if (m_DefaultLibraryHandle != null) { library_handle = m_DefaultLibraryHandle; ++library_handle.ReferenceCounter; return(library_handle); } Debug.WriteLine("Searching for libvlc.dll...", "LibVLC"); string executing_assembly_path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(Assembly.GetExecutingAssembly().Location)), "VLC"); string entry_assembly_path = null; if (Assembly.GetEntryAssembly() != null) { entry_assembly_path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(Assembly.GetEntryAssembly().Location)), "VLC"); } string current_directory_path = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "VLC"); string program_files_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "VideoLAN", "VLC"); foreach (string directory in new string[] { executing_assembly_path, entry_assembly_path, current_directory_path, program_files_path }) { if (System.IO.Directory.Exists(directory)) { try { m_DefaultLibraryHandle = GetOrLoadLibrary(directory); Debug.WriteLine(String.Format("Found libvlc.dll in directory {0}.", directory), "LibVLC"); return(m_DefaultLibraryHandle); } catch (Exception e) { Debug.WriteLine(String.Format("Caught exception of type {0} while loading libvlc.dll from {1}: {2}", e.GetType().Name, directory, e.Message), "LibVLC"); } } } throw new DllNotFoundException("No valid libvlc.dll could be found; VLC is probably not installed!"); } // lock(m_LibraryHandles) }
private static extern IntPtr GetProcAddress(LibraryHandle hModule, string lpProcName);