Exemple #1
0
 private static int gsapi_set_stdio(IntPtr lngGSInstance, StdioCallBack gsdll_stdin, StdioCallBack gsdll_stdout, StdioCallBack gsdll_stderr)
 {
     if (IntPtr.Size == 4)
     {
         return(gsapi_set_stdio32(lngGSInstance, gsdll_stdin, gsdll_stdout, gsdll_stderr));
     }
     else
     {
         return(gsapi_set_stdio64(lngGSInstance, gsdll_stdin, gsdll_stdout, gsdll_stderr));
     }
 }
Exemple #2
0
 /// <summary>Execute a Ghostscript command with a certain list of arguments</summary>
 /// <param name="sArgs">The list of the arguments</param>
 /// <returns>true if it succed, false otherwise</returns>
 private bool ExecuteGhostscriptCommand(string[] sArgs)
 {
     #region Variables
     int intReturn, intCounter, intElementCount;
     //The pointer to the current istance of the dll
     IntPtr     intGSInstanceHandle = IntPtr.Zero;
     object[]   aAnsiArgs;
     IntPtr[]   aPtrArgs;
     GCHandle[] aGCHandle;
     IntPtr     callerHandle, intptrArgs;
     GCHandle   gchandleArgs;
     #endregion
     #region Convert Unicode strings to null terminated ANSI byte arrays
     // Convert the Unicode strings to null terminated ANSI byte arrays
     // then get pointers to the byte arrays.
     intElementCount = sArgs.Length;
     aAnsiArgs       = new object[intElementCount];
     aPtrArgs        = new IntPtr[intElementCount];
     aGCHandle       = new GCHandle[intElementCount];
     //Convert the parameters
     for (intCounter = 0; intCounter < intElementCount; intCounter++)
     {
         aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]);
         aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned);
         aPtrArgs[intCounter]  = aGCHandle[intCounter].AddrOfPinnedObject();
     }
     gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned);
     intptrArgs   = gchandleArgs.AddrOfPinnedObject();
     #endregion
     #region Create a new istance of the library!
     intReturn = -1;
     try
     {
         intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle);
         //Be sure that we create an istance!
         if (intReturn < 0)
         {
             ClearParameters(ref aGCHandle, ref gchandleArgs);
             throw new ApplicationException("I can't create a new istance of Ghostscript please verify no other istance are running!");
         }
     }
     catch (BadImageFormatException formatException)//99.9% of time i'm just loading a 32bit dll in a 64bit enviroment!
     {
         ClearParameters(ref aGCHandle, ref gchandleArgs);
         //Check if i'm in a 64bit enviroment or a 32bit
         if (IntPtr.Size == 8) // 8 * 8 = 64
         {
             throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 64bit," +
                                                          "Please download any version above version 8.64 from the original website in the 64bit or x64 or AMD64 version!"));
         }
         else if (IntPtr.Size == 4) // 4 * 8 = 32
         {
             throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 32bit," +
                                                          "Please download any version above version 8.64 from the original website in the 32bit or x86 or i386 version!"));
         }
     }
     catch (DllNotFoundException ex)//in this case the dll we r using isn't the dll we expect
     {
         ClearParameters(ref aGCHandle, ref gchandleArgs);
         throw new ApplicationException("The gsdll32.dll wasn't found in default dlls search path" +
                                        "or is not in correct version (doesn't expose the required methods). Please download " +
                                        "at least the version 8.64 from the original website");
     }
     callerHandle = IntPtr.Zero;//remove unwanter handler
     #endregion
     #region Capture the I/O
     //Not working
     if (_bRedirectIO)
     {
         StdioCallBack stdinCallback  = new StdioCallBack(gsdll_stdin);
         StdioCallBack stdoutCallback = new StdioCallBack(gsdll_stdout);
         StdioCallBack stderrCallback = new StdioCallBack(gsdll_stderr);
         intReturn = gsapi_set_stdio(intGSInstanceHandle, stdinCallback, stdoutCallback, stderrCallback);
         if (output == null)
         {
             output = new StringBuilder();
         }
         else
         {
             output.Remove(0, output.Length);
         }
         myProcess = System.Diagnostics.Process.GetCurrentProcess();
         myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
     }
     #endregion
     intReturn = -1;//if nothing change it there is an error!
     //Ok now is time to call the interesting method
     try { intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs); }
     catch (Exception ex)
     {
         throw new ApplicationException(ex.Message, ex);
     }
     finally                                         //No matter what happen i MUST close the istance!
     {                                               //free all the memory
         ClearParameters(ref aGCHandle, ref gchandleArgs);
         gsapi_exit(intGSInstanceHandle);            //Close the istance
         gsapi_delete_instance(intGSInstanceHandle); //delete it
         //In case i was looking for output now stop
         if ((myProcess != null) && (_bRedirectIO))
         {
             myProcess.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
         }
     }
     //Conversion was successfull if return code was 0 or e_Quit
     return((intReturn == 0) | (intReturn == e_Quit));//e_Quit = -101
 }
Exemple #3
0
 private static extern int gsapi_set_stdio32(IntPtr lngGSInstance, StdioCallBack gsdll_stdin, StdioCallBack gsdll_stdout, StdioCallBack gsdll_stderr);
Exemple #4
0
        public bool Initialize(string[] sArgs)
        {
            #region Variables

            int intReturn, intCounter, intElementCount;
            //The pointer to the current istance of the dll
            IntPtr intGSInstanceHandle;
            object[] aAnsiArgs;
            IntPtr[] aPtrArgs;
            GCHandle[] aGCHandle;
            IntPtr callerHandle, intptrArgs;
            GCHandle gchandleArgs;

            #endregion

            #region Convert Unicode strings to null terminated ANSI byte arrays
            // Convert the Unicode strings to null terminated ANSI byte arrays
            // then get pointers to the byte arrays.
            intElementCount = sArgs.Length;
            aAnsiArgs = new object[intElementCount];
            aPtrArgs = new IntPtr[intElementCount];
            aGCHandle = new GCHandle[intElementCount];
            //Convert the parameters
            for (intCounter = 0; intCounter < intElementCount; intCounter++)
            {
                aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]);
                aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned);
                aPtrArgs[intCounter] = aGCHandle[intCounter].AddrOfPinnedObject();
            }
            gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned);
            intptrArgs = gchandleArgs.AddrOfPinnedObject();
            #endregion

            #region Create a new istance of the library!
            intReturn = -1;
            try
            {
                intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle);
                //Be sure that we create an istance!
                if (intReturn < 0)
                {
                    ClearParameters(ref aGCHandle, ref gchandleArgs);
                    throw new ApplicationException("I can't create a new istance of Ghostscript please verify no other istance are running!");
                }
            }
            catch (DllNotFoundException)
            {//in this case the dll we r using isn't the dll we expect
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                throw new ApplicationException("The gsdll32.dll wasn't found in default dlls search path " +
                    "or is not in correct version (doesn't expose the required methods).\nPlease download, install " +
                    "GPL Ghostscript from http://sourceforge.net/projects/ghostscript/files\nand/or set the appropriate environment variable.");

            }
            callerHandle = IntPtr.Zero;//remove unwanter handler
            #endregion
            #region Capture the I/O

            StdioCallBack stdinCallback = new StdioCallBack(gsdll_stdin);
            StdioCallBack stdoutCallback = new StdioCallBack(gsdll_stdout);
            StdioCallBack stderrCallback = new StdioCallBack(gsdll_stderr);
            intReturn = gsapi_set_stdio(intGSInstanceHandle, stdinCallback, stdoutCallback, stderrCallback);
            //if (output == null) output = new StringBuilder();
            //else output.Remove(0, output.Length);
            //myProcess = System.Diagnostics.Process.GetCurrentProcess();
            //myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);

            #endregion
            intReturn = -1;//if nothing change it there is an error!
            //Ok now is time to call the interesting method
            try
            {
                intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex);
            }
            finally//No matter what happen i MUST close the istance!
            {   //free all the memory
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                gsapi_exit(intGSInstanceHandle);//Close the istance
                gsapi_delete_instance(intGSInstanceHandle);//delete it
                //In case i was looking for output now stop
                if (myProcess != null) myProcess.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
            }
            //Conversion was successfull if return code was 0 or e_Quit
            return (intReturn == 0) | (intReturn == e_Quit);//e_Quit = -101
        }
Exemple #5
0
 private static extern int gsapi_set_stdio(IntPtr lngGSInstance, StdioCallBack gsdll_stdin, StdioCallBack gsdll_stdout, StdioCallBack gsdll_stderr);
Exemple #6
0
        private bool ExecuteGhostscriptCommand(string[] sArgs)
        {
            IntPtr pinstance = IntPtr.Zero;
            int    length    = sArgs.Length;

            object[]   objArray  = new object[length];
            IntPtr[]   numArray  = new IntPtr[length];
            GCHandle[] aGCHandle = new GCHandle[length];
            for (int index = 0; index < length; ++index)
            {
                objArray[index]  = (object)PDFConvert.StringToAnsiZ(sArgs[index]);
                aGCHandle[index] = GCHandle.Alloc(objArray[index], GCHandleType.Pinned);
                numArray[index]  = aGCHandle[index].AddrOfPinnedObject();
            }
            GCHandle gchandleArgs = GCHandle.Alloc((object)numArray, GCHandleType.Pinned);
            IntPtr   argv         = gchandleArgs.AddrOfPinnedObject();
            int      num1         = -1;

            try
            {
                if (PDFConvert.gsapi_new_instance(out pinstance, this._objHandle) < 0)
                {
                    this.ClearParameters(ref aGCHandle, ref gchandleArgs);
                    throw new ApplicationException("I can't create a new istance of Ghostscript please verify no other istance are running!");
                }
            }
            catch (BadImageFormatException ex)
            {
                this.ClearParameters(ref aGCHandle, ref gchandleArgs);
                if (IntPtr.Size == 8)
                {
                    throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 64bit,Please download any version above version 8.64 from the original website in the 64bit or x64 or AMD64 version!"));
                }
                if (IntPtr.Size == 4)
                {
                    throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 32bit,Please download any version above version 8.64 from the original website in the 32bit or x86 or i386 version!"));
                }
            }
            catch (DllNotFoundException ex)
            {
                this.ClearParameters(ref aGCHandle, ref gchandleArgs);
                throw new ApplicationException("The gsdll32.dll wasn't found in default dlls search pathor is not in correct version (doesn't expose the required methods). Please download at least the version 8.64 from the original website");
            }
            IntPtr num2 = IntPtr.Zero;

            if (this._bRedirectIO)
            {
                StdioCallBack gsdll_stdin  = new StdioCallBack(this.gsdll_stdin);
                StdioCallBack gsdll_stdout = new StdioCallBack(this.gsdll_stdout);
                StdioCallBack gsdll_stderr = new StdioCallBack(this.gsdll_stderr);
                num1 = PDFConvert.gsapi_set_stdio(pinstance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
                if (this.output == null)
                {
                    this.output = new StringBuilder();
                }
                else
                {
                    this.output.Remove(0, this.output.Length);
                }
                this.myProcess = Process.GetCurrentProcess();
                this.myProcess.OutputDataReceived += new DataReceivedEventHandler(this.SaveOutputToImage);
            }
            int num3 = -1;

            try
            {
                num3 = PDFConvert.gsapi_init_with_args(pinstance, length, argv);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex);
            }
            finally
            {
                this.ClearParameters(ref aGCHandle, ref gchandleArgs);
                PDFConvert.gsapi_exit(pinstance);
                PDFConvert.gsapi_delete_instance(pinstance);
                if (this.myProcess != null && this._bRedirectIO)
                {
                    this.myProcess.OutputDataReceived -= new DataReceivedEventHandler(this.SaveOutputToImage);
                }
            }
            return(num3 == 0 | num3 == -101);
        }
Exemple #7
0
        public bool Initialize(string[] sArgs)
        {
            #region Variables

            int intReturn, intCounter, intElementCount;
            //The pointer to the current istance of the dll
            IntPtr     intGSInstanceHandle;
            object[]   aAnsiArgs;
            IntPtr[]   aPtrArgs;
            GCHandle[] aGCHandle;
            IntPtr     callerHandle, intptrArgs;
            GCHandle   gchandleArgs;

            #endregion

            #region Convert Unicode strings to null terminated ANSI byte arrays
            // Convert the Unicode strings to null terminated ANSI byte arrays
            // then get pointers to the byte arrays.
            intElementCount = sArgs.Length;
            aAnsiArgs       = new object[intElementCount];
            aPtrArgs        = new IntPtr[intElementCount];
            aGCHandle       = new GCHandle[intElementCount];
            //Convert the parameters
            for (intCounter = 0; intCounter < intElementCount; intCounter++)
            {
                aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]);
                aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned);
                aPtrArgs[intCounter]  = aGCHandle[intCounter].AddrOfPinnedObject();
            }
            gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned);
            intptrArgs   = gchandleArgs.AddrOfPinnedObject();
            #endregion

            #region Create a new istance of the library!
            intReturn = -1;
            try
            {
                intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle);
                //Be sure that we create an istance!
                if (intReturn < 0)
                {
                    ClearParameters(ref aGCHandle, ref gchandleArgs);
                    throw new ApplicationException("I can't create a new istance of Ghostscript please verify no other istance are running!");
                }
            }
            catch (DllNotFoundException)
            {//in this case the dll we r using isn't the dll we expect
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                throw new ApplicationException("The gsdll32.dll wasn't found in default dlls search path " +
                                               "or is not in correct version (doesn't expose the required methods).\nPlease download, install " +
                                               "GPL Ghostscript from http://sourceforge.net/projects/ghostscript/files\nand/or set the appropriate environment variable.");
            }
            callerHandle = IntPtr.Zero;//remove unwanter handler
            #endregion
            #region Capture the I/O

            StdioCallBack stdinCallback  = new StdioCallBack(gsdll_stdin);
            StdioCallBack stdoutCallback = new StdioCallBack(gsdll_stdout);
            StdioCallBack stderrCallback = new StdioCallBack(gsdll_stderr);
            intReturn = gsapi_set_stdio(intGSInstanceHandle, stdinCallback, stdoutCallback, stderrCallback);
            //if (output == null) output = new StringBuilder();
            //else output.Remove(0, output.Length);
            //myProcess = System.Diagnostics.Process.GetCurrentProcess();
            //myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);

            #endregion
            intReturn = -1;//if nothing change it there is an error!
            //Ok now is time to call the interesting method
            try
            {
                intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex);
            }
            finally                                         //No matter what happen i MUST close the istance!
            {                                               //free all the memory
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                gsapi_exit(intGSInstanceHandle);            //Close the istance
                gsapi_delete_instance(intGSInstanceHandle); //delete it
                //In case i was looking for output now stop
                if (myProcess != null)
                {
                    myProcess.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
                }
            }
            //Conversion was successfull if return code was 0 or e_Quit
            return((intReturn == 0) | (intReturn == e_Quit));//e_Quit = -101
        }
Exemple #8
0
        public bool Initialize(string[] sArgs)
        {
            #region Variables

            int intReturn, intCounter, intElementCount;
            //The pointer to the current instance of the dll
            IntPtr     intGSInstanceHandle;
            object[]   aAnsiArgs;
            IntPtr[]   aPtrArgs;
            GCHandle[] aGCHandle;
            IntPtr     callerHandle, intptrArgs;
            GCHandle   gchandleArgs;

            #endregion

            #region Convert Unicode strings to null-terminated UTF8 byte arrays
            // Convert the Unicode strings to null-terminated UTF8 byte arrays
            // then get pointers to the byte arrays.
            intElementCount = sArgs.Length;
            aAnsiArgs       = new object[intElementCount];
            aPtrArgs        = new IntPtr[intElementCount];
            aGCHandle       = new GCHandle[intElementCount];
            //Convert the parameters
            for (intCounter = 0; intCounter < intElementCount; intCounter++)
            {
                aAnsiArgs[intCounter] = NativeUtf8FromString(sArgs[intCounter]);
                aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned);
                aPtrArgs[intCounter]  = aGCHandle[intCounter].AddrOfPinnedObject();
            }
            gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned);
            intptrArgs   = gchandleArgs.AddrOfPinnedObject();
            #endregion

            #region Create a new instance of the library!
            intReturn = -1;
            try
            {
                intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle);
                //Be sure that we create an instance!
                if (intReturn < 0)
                {
                    ClearParameters(ref aGCHandle, ref gchandleArgs);
                    throw new ApplicationException(GSDLL_INSTANCE);
                }
            }
            catch (DllNotFoundException)
            {//in this case the dll we r using isn't the dll we expect
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                throw new ApplicationException(GSDLL_NOT_FOUND);
            }
            callerHandle = IntPtr.Zero;//remove unwanter handler
            #endregion
            #region Capture the I/O

            StdioCallBack stdinCallback  = new StdioCallBack(gsdll_stdin);
            StdioCallBack stdoutCallback = new StdioCallBack(gsdll_stdout);
            StdioCallBack stderrCallback = new StdioCallBack(gsdll_stderr);
            intReturn = gsapi_set_stdio(intGSInstanceHandle, stdinCallback, stdoutCallback, stderrCallback);
            //if (output == null) output = new StringBuilder();
            //else output.Remove(0, output.Length);
            //myProcess = System.Diagnostics.Process.GetCurrentProcess();
            //myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);

            #endregion
            intReturn = -1;//if nothing change it there is an error!
            //Ok now is time to call the interesting method
            try
            {
                intReturn = gsapi_set_arg_encoding(intGSInstanceHandle, GS_ARG_ENCODING_UTF8);
                intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex);
            }
            finally                                         //No matter what happen, i MUST close the instance!
            {                                               //free all the memory
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                gsapi_exit(intGSInstanceHandle);            //Close the instance
                gsapi_delete_instance(intGSInstanceHandle); //delete it
                //In case i was looking for output now stop
                if (myProcess != null)
                {
                    myProcess.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
                }
            }
            //Conversion was successfull if return code was 0 or e_Quit
            return((intReturn == 0) | (intReturn == e_Quit));//e_Quit = -101
        }
Exemple #9
0
 public static extern int gsapi_set_stdio(IntPtr instance, StdioCallBack stdin_fn, StdioCallBack stdout_fn, StdioCallBack stderr_fn);
Exemple #10
0
 private static int gsapi_set_stdio(IntPtr lngGSInstance, StdioCallBack gsdll_stdin, StdioCallBack gsdll_stdout, StdioCallBack gsdll_stderr)
 {
     if (IntPtr.Size > 4)
         return gsapi_set_stdio64(lngGSInstance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
     else
         return gsapi_set_stdio32(lngGSInstance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
 }
Exemple #11
0
        private bool ExecuteGhostscriptCommand(string[] sArgs)
        {
            #region Variables
            int intCounter, intElementCount;
            //The pointer to the current istance of the dll
            
            object[] aAnsiArgs;
            
            //Process proc = Process.GetCurrentProcess();

            #endregion
            //PJsoft.WebServicesBase.Log.writeInfo(string.Format("Input parameters: {0}", string.Join(";",sArgs)));
            //PJsoft.WebServicesBase.Log.writeInfo(string.Format("Start of GhostScrip command - size of workingset: {0} kB", System.Environment.WorkingSet/1024));
            #region Convert Unicode strings to null terminated ANSI byte arrays
            // Convert the Unicode strings to null terminated ANSI byte arrays
            // then get pointers to the byte arrays.
            intElementCount = sArgs.Length;
            aAnsiArgs = new object[intElementCount];
            aPtrArgs = new IntPtr[intElementCount];
            aGCHandle = new GCHandle[intElementCount];
            //Convert the parameters
            for (intCounter = 0; intCounter < intElementCount; intCounter++)
            {
                aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]);
                aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned);
                aPtrArgs[intCounter] = aGCHandle[intCounter].AddrOfPinnedObject();
            }
            gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned);
            intptrArgs = gchandleArgs.AddrOfPinnedObject();
            //PJsoft.WebServicesBase.Log.writeInfo(string.Format("GhostScrip command - size of workingset after convert parameters: {0} kB", System.Environment.WorkingSet/1024));
            #endregion
            #region Create a new istance of the library!
            intReturn = -1;
            try
            {
                intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle);
                //Be sure that we create an istance!
                if (intReturn < 0)
                {
                    ClearParameters(ref aGCHandle, ref gchandleArgs);
                    throw new ApplicationException("I can't create a new istance of Ghostscript please verify no other istance are running!");
                }
            }
            catch (BadImageFormatException)//99.9% of time i'm just loading a 32bit dll in a 64bit enviroment!
            {
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                //Check if i'm in a 64bit enviroment or a 32bit
                if (IntPtr.Size == 8) // 8 * 8 = 64
                {
                    throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 64bit," +
                    "Please download any version above version 8.64 from the original website in the 64bit or x64 or AMD64 version!"));
                }
                else if (IntPtr.Size == 4) // 4 * 8 = 32
                {
                    throw new ApplicationException(string.Format("The gsdll32.dll you provide is not compatible with the current architecture that is 32bit," +
                    "Please download any version above version 8.64 from the original website in the 32bit or x86 or i386 version!"));
                }
            }
            catch (DllNotFoundException)//in this case the dll we r using isn't the dll we expect
            {
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                throw new ApplicationException("The gsdll32.dll wasn't found in default dlls search path" +
                    "or is not in correct version (doesn't expose the required methods). Please download " +
                    "at least the version 8.64 from the original website");
            }
            callerHandle = IntPtr.Zero;//remove unwanter handler
            #endregion
            //PJsoft.WebServicesBase.Log.writeInfo(string.Format("GhostScrip command - size of workingset after creating new instance: {0} kB", System.Environment.WorkingSet/1024));
            #region Capture the I/O
            //Not working
            if (_bRedirectIO)
            {
                StdioCallBack stdinCallback = new StdioCallBack(gsdll_stdin);
                StdioCallBack stdoutCallback = new StdioCallBack(gsdll_stdout);
                StdioCallBack stderrCallback = new StdioCallBack(gsdll_stderr);
                intReturn = gsapi_set_stdio(intGSInstanceHandle, stdinCallback, stdoutCallback, stderrCallback);
                if (output == null) output = new StringBuilder();
                else output.Remove(0, output.Length);
                myProcess = System.Diagnostics.Process.GetCurrentProcess();
                myProcess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
            }
            #endregion
            intReturn = -1;//if nothing change it there is an error!
            //Ok now is time to call the interesting method
            try
            {
                intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs);
                //PJsoft.WebServicesBase.Log.writeInfo(string.Format("GhostScrip command - size of workingset after converting: {0} kB", System.Environment.WorkingSet/1024));
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex);
            }
            finally//No matter what happen i MUST close the istance!
            {   //free all the memory
                ClearParameters(ref aGCHandle, ref gchandleArgs);
                gsapi_exit(intGSInstanceHandle);//Close the istance
                gsapi_delete_instance(intGSInstanceHandle);//delete it
                //In case i was looking for output now stop
                if ((myProcess != null) && (_bRedirectIO)) myProcess.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(SaveOutputToImage);
            }
            //Conversion was successfull if return code was 0 or e_Quit
            //PJsoft.WebServicesBase.Log.writeInfo(string.Format("GhostScrip command - size of workingset after freeing memory: {0} kB", System.Environment.WorkingSet/1024));            
            

            return (intReturn == 0) | (intReturn == e_Quit);//e_Quit = -101
        }
Exemple #12
0
 public static extern int gsapi_set_stdio(IntPtr instance, StdioCallBack stdin_fn, StdioCallBack stdout_fn, StdioCallBack stderr_fn);