Пример #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)
            {
                NativeMethods64.CreateAPIInstance(out gsInstancePtr, IntPtr.Zero);
                try
                {
                    int result = NativeMethods64.InitAPI(gsInstancePtr, args.Length, args);

                    if (result < 0)
                    {
                        throw new ExternalException("Ghostscript conversion error", result);
                    }
                }
                finally
                {
                    Cleanup(gsInstancePtr);
                }
            }
        }
Пример #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)
 {
     NativeMethods64.ExitAPI(gsInstancePtr);
     NativeMethods64.DeleteAPIInstance(gsInstancePtr);
 }