Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

gsapi_new_instance (gsapi)
 
.
Summary
Creates a new instance of Ghostscript. This instance is passed to most other gsapi functions.

Creates a new instance of Ghostscript. This instance is passed to most other gsapi functions.

C# Signature:

   [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
   private static extern int gsapi_new_instance(ref System.IntPtr pinstance, System.IntPtr handle);

VB Signature:

  <DllImport("gsdll32.dll", CharSet:= CharSet.Ansi, CallingConvention:= CallingConvention.StdCall)> _
   Private Shared Function gsapi_new_instance(ByRef pinstance As System.IntPtr, ByVal handle As System.IntPtr) As Integer
   End Function

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

When working with the gsapi.dll, start with the gsapi_revision function, get that working. Then get this api working next.

Sample Code:

   /* Keep this variable at a class scope. It will be used by almost all of the gsapi functions */
   System.IntPtr pinstance= IntPtr.Zero;

   private void button1_Click(object sender, EventArgs e)
   {
   /* Pass in the reference to pinstance, declared above. Assume "this" is a Windows Form, so it will have a Handle */

    int retVal = gsapi_new_instance(ref pinstance, this.Handle);
   }

Documentation

Sample Code:

// c# console program to call Ghostscript

using System;

using System.Runtime.InteropServices;

namespace GPL

{

    public class Ghostscript
    {
    [StructLayout(LayoutKind.Sequential)]
    public struct GSVersion
    {
        public string product;
        public string copyright;
        public int revision;
        public int revisionDate;
    }

    [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    private static extern int gsapi_revision(ref GSVersion version, int len);

    [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    private static extern int gsapi_new_instance(ref System.IntPtr pinstance, System.IntPtr handle);

    [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    private static extern int gsapi_init_with_args(IntPtr pInstance, int argc, [In, Out] string[] argv);

    [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    private static extern int gsapi_exit(IntPtr instance);

    [DllImport("gsdll32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    private static extern void gsapi_delete_instance(System.IntPtr pinstance);

    public static void getVersion(ref GSVersion version)
    {
        gsapi_revision(ref version, Marshal.SizeOf(version));
    }

    public static void run(string[] argv)
    {
        IntPtr inst = IntPtr.Zero;
        int code = gsapi_new_instance(ref inst, IntPtr.Zero);
        if (code != 0) return;
        code = gsapi_init_with_args(inst, argv.Length, argv);
        gsapi_exit(inst);
        gsapi_delete_instance(inst);
    }
    }
    class Program
    {
    static void Main(string[] args)
    {
        Ghostscript.GSVersion gsVer = new Ghostscript.GSVersion();
        Ghostscript.getVersion(ref gsVer);
        // execute this command, to convert pdf to tiff
        // "C:\Program Files (x86)\gs\gs9.00\bin\gswin32c" -q -sOutputFile=D:\temp\Planung.tif -dNOPAUSE -dBATCH -P- -dSAFER -sDEVICE#tiffpack  -r100 D:\temp\Planung.pdf
        string[] argv = { "flashReader", "-q", "-sOutputFile=C:\\temp\\Outfile.tif", "-dNOPAUSE", "-dBATCH", "-P-", "-dSAFER", "-sDEVICE=tiffpack", "-r100", "C:\\temp\\Infile.pdf" };
        Ghostscript.run(argv);
    }
    }

}

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions