/// <summary> /// Initializes a new instance of the Ghostscript.NET.GhostscriptLibrary class /// from the GhostscriptVersionInfo object. /// </summary> /// <param name="version">GhostscriptVersionInfo instance that tells which Ghostscript library to use.</param> /// <param name="fromMemory">Tells if the Ghostscript should be loaded from the memory or directly from the disk.</param> public GhostscriptLibrary(GhostscriptVersionInfo version, bool fromMemory) { // check if Ghostscript version is specified if (version == null) { throw new ArgumentNullException("version"); } // check if specified Ghostscript native library exist on the disk if (!File.Exists(version.DllPath)) { throw new DllNotFoundException("Ghostscript native library could not be found."); } _version = version; _loadedFromMemory = fromMemory; // check if library is compatibile with a running process if (Environment.Is64BitProcess != NativeLibraryHelper.Is64BitLibrary(version.DllPath)) { // throw friendly gsdll incompatibility message this.ThrowIncompatibileNativeGhostscriptLibraryException(); } // check wether we need to load Ghostscript native library from the memory or a disk if (fromMemory) { // load native Ghostscript library into the memory byte[] buffer = File.ReadAllBytes(version.DllPath); // create DynamicNativeLibrary instance from the memory buffer _library = new DynamicNativeLibrary(buffer); } else { // create DynamicNativeLibrary instance from the local disk file _library = new DynamicNativeLibrary(version.DllPath); } // get and map native library symbols this.Initialize(); }
/// <summary> /// Initializes a new instance of the Ghostscript.NET.GhostscriptLibrary class /// from the native library represented as the memory buffer. /// </summary> /// <param name="library">Memory buffer representing native Ghostscript library.</param> public GhostscriptLibrary(byte[] library) { if (library == null) { throw new ArgumentNullException("library"); } // check if library is compatibile with a running process if (Environment.Is64BitProcess != NativeLibraryHelper.Is64BitLibrary(library)) { // throw friendly gsdll incompatibility message this.ThrowIncompatibileNativeGhostscriptLibraryException(); } // create DynamicNativeLibrary instance from the memory buffer _library = new DynamicNativeLibrary(library); // set the flag that the library is loaded from the memory _loadedFromMemory = true; // get and map native library symbols this.Initialize(); }