Exemplo n.º 1
0
        /*
         * This code was adapted from Matthew Ephraim's Ghostscript.Net project
         * external dll definitions moved into NativeMethods to
         * satisfy FxCop requirements
         * https://github.com/mephraim/ghostscriptsharp
         */

        /// <summary>
        /// Calls the Ghostscript API with a collection of arguments to be passed to it
        /// </summary>
        public static void CallAPI(string[] args)
        {
            // Get a pointer to an instance of the Ghostscript API and run the API with the current arguments
            IntPtr gsInstancePtr;

            lock (resourceLock)
            {
                NativeMethods32.CreateAPIInstance(out gsInstancePtr, IntPtr.Zero);
                try
                {
                    int result = NativeMethods32.InitAPI(gsInstancePtr, args.Length, args);

                    if (result < 0)
                    {
                        throw new ExternalException("Ghostscript conversion error", result);
                    }
                }
                finally
                {
                    Cleanup(gsInstancePtr);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Frees up the memory used for the API arguments and clears the Ghostscript API instance
 /// </summary>
 private static void Cleanup(IntPtr gsInstancePtr)
 {
     NativeMethods32.ExitAPI(gsInstancePtr);
     NativeMethods32.DeleteAPIInstance(gsInstancePtr);
 }