⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dll.htm

📁 GhostScript的源代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:

<blockquote>
<font size="-1"><pre>int
gsdll_callback(int message, char *str, unsigned long count)
{
char *p;
    switch (message) {
        case GSDLL_STDIN:
            p = fgets(str, count, stdin);
            if (p)
                return strlen(str);
            else
                return 0;
        case GSDLL_STDOUT:
            if (str != (char *)NULL)
                fwrite(str, 1, count, stdout);
            return count;
        case GSDLL_DEVICE:
            fprintf(stdout,"Callback: DEVICE %p %s\n", str,
                count ? "open" : "close");
            break;
        case GSDLL_SYNC:
            fprintf(stdout,"Callback: SYNC %p\n", str);
            break;
        case GSDLL_PAGE:
            fprintf(stdout,"Callback: PAGE %p\n", str);
            break;
        case GSDLL_SIZE:
            fprintf(stdout,"Callback: SIZE %p width=%d height=%d\n", str,
                (int)(count &amp; 0xffff), (int)((count&gt;&gt;16) &amp; 0xffff) );
            break;
        case GSDLL_POLL:
            return 0; /* no error */
        default:
            fprintf(stdout,"Callback: Unknown message=%d\n",message);
            break;
    }
    return 0;
}
</pre></font>

<table cellpadding=0 cellspacing=0>
<tr><th colspan=5 bgcolor="#CCCC00"><hr><font size="+1">Messages used by callback</font><hr>
<tr valign=bottom>
	<th align=left>Symbol
	<td>&nbsp;&nbsp;
	<th align=left>
	<td>&nbsp;&nbsp;
	<th align=left>Use
<tr>	<td colspan=5><hr>
<tr valign=top>	<td><b><tt>GSDLL_STDIN</tt></b>
	<td>&nbsp;
	<td>1
	<td>&nbsp;
	<td>get <b><tt>count</tt></b> characters to <b><tt>str</tt></b> from stdin, return number of characters read
<tr valign=top>	<td><b><tt>GSDLL_STDOUT</tt></b>
	<td>&nbsp;
	<td>2
	<td>&nbsp;
	<td>put <b><tt>count</tt></b> characters from <b><tt>str</tt></b>
		to stdout, return number of characters written
<tr valign=top>	<td><b><tt>GSDLL_DEVICE</tt></b>
	<td>&nbsp;
	<td>3
	<td>&nbsp;
	<td>device <b><tt>str</tt></b> has been opened if
		<b><tt>count</tt></b>&nbsp;=&nbsp;1, closed if
		<b><tt>count</tt></b>&nbsp;=&nbsp;0
<tr valign=top>	<td><b><tt>GSDLL_SYNC</tt></b>
	<td>&nbsp;
	<td>4
	<td>&nbsp;
	<td>sync_output for device <b><tt>str</tt></b>
<tr valign=top>	<td><b><tt>GSDLL_PAGE</tt></b>
	<td>&nbsp;
	<td>5
	<td>&nbsp;
	<td>output_page for device <b><tt>str</tt></b>
<tr valign=top>	<td><b><tt>GSDLL_SIZE</tt></b>
	<td>&nbsp;
	<td>6
	<td>&nbsp;
	<td>resize for device <b><tt>str</tt></b>:
		LOWORD(<b><tt>count</tt></b>) is new <b><tt>xsize</tt></b>,
		HIWORD(<b><tt>count</tt></b>) is new <b><tt>ysize</tt></b>
<tr valign=top>	<td><b><tt>GSDLL_POLL</tt></b>
	<td>&nbsp;
	<td>7
	<td>&nbsp;
	<td>Called from <b><tt>gp_check_interrupt()</tt></b><br>
		Can be used by the caller to poll the message queue.
		Normally returns 0.  To abort
		<b><tt>gsdll_execute_cont()</tt></b>, return a non-zero
		error code until <b><tt>gsdll_execute_cont()</tt></b>
		returns.
</table>
</blockquote>
</blockquote>

<hr>

<h1><a name="OS2_device"></a>Ghostscript DLL device for OS/2</h1>

<p>
The <b><tt>os2dll</tt></b> device is provided in the Ghostscript DLL for
use by the caller.  No drawing facilities are provided by the DLL because
the DLL may be loaded by a text-only (non-PM) application.  The caller is
notified via the <b><tt>gsdll_callback()</tt></b> when a new
<b><tt>os2dll</tt></b> device is opened or closed
(<b><tt>GSDLL_DEVICE</tt></b>), when the window should be redrawn
(<b><tt>GSDLL_SYNC</tt></b> or <b><tt>GSDLL_PAGE</tt></b>) or when the
bitmap size changes (<b><tt>GSDLL_SIZE</tt></b>).
Note that more than one <b><tt>os2dll</tt></b> device may be opened.

<h2><a name="OS2_bmp"></a><b><tt>gsdll_get_bitmap()</tt></b></h2>

<blockquote>
<b><tt>gsdll_get_bitmap()</tt></b> returns a pointer to a bitmap in BMP
format.  The <b><tt>os2dll</tt></b> device draws into this bitmap.

<blockquote>
<pre>unsigned long gsdll_get_bitmap(unsigned char *device, unsigned char **pbitmap);
 /* return in pbitmap the address of the bitmap */
 /* device is a pointer to Ghostscript os2dll device from GSDLL_DEVICE message */
</pre></blockquote>

<p>
The caller can then display the bitmap however it likes, but should lock
the bitmap with <b><tt>gsdll_lock_device()</tt></b> before painting from
it, and unlock it afterwards.  The bitmap address does not change until the
<b><tt>os2dll</tt></b> device is closed; however the bitmap size and
palette may change whenever the bitmap is not locked.
</blockquote>

<h2><a name="OS2_example"></a>Example DLL usage for OS/2</h2>

<p>
The example here shows a minimal usage of the Ghostscript DLL under OS/2.
The sample callback function above is needed.

<blockquote>
<font size="-1"><pre>#define INCL_DOS
#include &lt;os2.h&gt;
#include &lt;stdio.h&gt;
#include "gsdll.h"

PFN_gsdll_init pgsdll_init;
PFN_gsdll_execute_begin pgsdll_execute_begin;
PFN_gsdll_execute_cont pgsdll_execute_cont;
PFN_gsdll_execute_end pgsdll_execute_end;
PFN_gsdll_exit pgsdll_exit;

HMODULE hmodule_gsdll;
char buf[256];

int
main(int argc, char *argv[])
{
int code;
APIRET rc;
    if (!DosLoadModule(buf, sizeof(buf), "GSDLL2", &amp;hmodule_gsdll)) {
        fprintf(stderr, "Loaded GSDLL2\n");
        DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_init", (PFN *)(&amp;pgsdll_init));
        DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_begin", (PFN *)(&amp;pgsdll_execute_begin));
        DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_cont", (PFN *)(&amp;pgsdll_execute_cont));
        DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_end", (PFN *)(&amp;pgsdll_execute_end));
        DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_exit", (PFN *)(&amp;pgsdll_exit));
    }
    else {
        fprintf(stderr, "Can't load GSDLL2\n");
    }

    code = (*pgsdll_init)(gsdll_callback, NULL, argc, argv);
    fprintf(stdout,"gsdll_init returns %d\n", code);
    code = (*pgsdll_execute_begin)();
    if (code==0) {
        while (fgets(buf, sizeof(buf), stdin)) {
            code = (*pgsdll_execute_cont)(buf, strlen(buf));
            fprintf(stdout,"gsdll_execute returns %d\n", code);
            if (code &lt; 0)
               break;
        }
        if (!code)
            code = (*pgsdll_execute_end)();
        code = (*pgsdll_exit)();
        fprintf(stdout,"gsdll_exit returns %d\n", code);
    }
    rc = DosFreeModule(hmodule_gsdll);
    fprintf(stdout,"DosFreeModule returns %d\n", rc);
    return 0;
}
</pre></font></blockquote>

<hr>

<h1><a name="Win_device"></a>Ghostscript DLL device for MS Windows</h1>

<p>
The <b><tt>mswindll</tt></b> device is provided in the Ghostscript DLL for
use by the caller.  The caller is notified via the
<b><tt>gsdll_callback()</tt></b> when a new <b><tt>mswindll</tt></b> device
is opened or closed (<b><tt>GSDLL_DEVICE</tt></b>), when the window should
be redrawn (<b><tt>GSDLL_SYNC</tt></b> or <b><tt>GSDLL_PAGE</tt></b>) or
when the bitmap size changes (<b><tt>GSDLL_SIZE</tt></b>).  Note that more
than one <b><tt>mswindll</tt></b> device may be opened.

<p>
Four DLL functions are available to use the <b><tt>mswindll</tt></b>
device.

<h2><a name="Win_copydib"></a><b><tt>gsdll_copy_dib()</tt></b></h2>

<blockquote>
Copy the <b><tt>mswindll</tt></b> bitmap to the clipboard.

<blockquote>
<pre>HGLOBAL GSDLLAPI gsdll_copy_dib(unsigned char *device);
 /* make a copy of the device bitmap and return shared memory handle to it */
 /* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
</pre></blockquote>
</blockquote>

<h2><a name="Win_copypalette"></a><b><tt>gsdll_copy_palette()</tt></b></h2>

<blockquote>
Copy the <b><tt>mswindll</tt></b> palette to the clipboard.

<blockquote>
<pre>HPALETTE GSDLLAPI gsdll_copy_palette(unsigned char *device);
/* make a copy of the device palette and return a handle to it */
/* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
</pre></blockquote>
</blockquote>

<h2><a name="Win_draw"></a><b><tt>gsdll_draw()</tt></b></h2>

<blockquote>
Display output from the <b><tt>mswindll</tt></b> device.  The caller should
create a window and call <b><tt>gsdll_draw()</tt></b> in response to the
<b><tt>WM_PAINT</tt></b> message.  The device context <b><tt>hdc</tt></b>
must be for a device because <b><tt>SetDIBitsToDevice()</tt></b> is used.

<blockquote>
<pre>void GSDLLAPI gsdll_draw(unsigned char *device, HDC hdc,
                                  LPRECT dest, LPRECT src);
/* copy the rectangle src from the device bitmap */
/* to the rectangle dest on the device given by hdc */
/* hdc must be a device context for a device (NOT a bitmap) */
/* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
</pre></blockquote>
</blockquote>

<h2><a name="Win_get_row"></a><b><tt>gsdll_get_bitmap_row()</tt></b></h2>

<blockquote>
Get a BMP header, a palette, and a pointer to a row in the bitmap.  This
function exists to allow the bitmap to be copied to a file or structured
storage without the overhead of having two copies of the bitmap in memory
at the same time.

<p>
Ghostscript can change the palette while the device is locked.  Do not call
this function while Ghostscript is busy.

<blockquote>
<pre>int GSDLLAPI gsdll_get_bitmap_row(unsigned char *device, LPBITMAPINFOHEADER pbmih,
    LPRGBQUAD prgbquad, LPBYTE *ppbyte, unsigned int row)
/* If pbmih nonzero, copy the BITMAPINFOHEADER.
 * If prgbquad nonzero, copy the palette.
 *   number of entries copied is given by pbmih-&gt;biClrUsed
 * If ppbyte nonzero, return pointer to row.
 *   pointer is only valid while device is locked
 */
</pre></blockquote>
</blockquote>

<hr>

<h1><a name="Win16"></a>Ghostscript DLL Device for 16-bit MS Windows</h1>

<p>
This platform has the most problems of the three.  Support for it may be
dropped in future.

<p>
The Win16 DLL <b><tt>GSDLL16.DLL</tt></b> is a large-memory model DLL with
far static data.  Due to the limitations of 16-bit MS Windows, the DLL can
be used by only one program at a time.

<p>
However, <b><tt>GSDLL16</tt></b> is marked as having SINGLE SHARED data
segments, allowing multiple applications to load it with no error
indication.  (The DLL wouldn't load at all if MULTIPLE NONSHARED was used).
Nonetheless, <b>it cannot be used by more than one application at a
time</b>, so applications loading <b><tt>GSDLL16</tt></b> should check the
return value of <b><tt>gsdll_init()</tt></b>: if this value is non-zero,
then <b><tt>GSDLL16</tt></b> is already in use by another application and
should <b><em>not</em></b> be used: <b><tt>GSDLL16</tt></b> should be
unloaded immediately using <b><tt>FreeLibrary()</tt></b>, or the calling
program should quit without attempting to use the library..

<p>
The segmented architecture of the Intel 80286 causes the usual amount of
grief when using <b><tt>GSDLL16</tt></b>.  Because the callback is called
from the DLL, which is using a different data segment, the callback must be
declared as <b><tt>_far&nbsp;_export</tt></b>:

<blockquote>
<pre>int _far _export gsdll_callback(int message, char *str, unsigned long count);
</pre></blockquote>

<p>
Instead of giving <b><tt>gsdll_init()</tt></b> the address of
<b><tt>gsdll_callback()</tt></b>, it should instead be given the address of
a thunk created by <b><tt>MakeProcInstance</tt></b>.  This thunk changes
the data segment back to that used by the caller:

<blockquote>
<pre>FARPROC lpfnCallback;
lpfnCallback = (FARPROC)MakeProcInstance((FARPROC)gsdll_callback, hInstance);
code = (*pgsdll_init)((GSDLL_CALLBACK)lpfnCallback, NULL, argc, argv);
if (!code) {
    fprintf(stderr, "GSDLL16 is already in use\n");
    return -1;
}
</pre></blockquote>

<!-- [2.0 end contents] ---------------------------------------------------- -->

<!-- [3.0 begin visible trailer] ------------------------------------------- -->
<hr>

<font size=2>

<p>Copyright &copy; 1996, 1997, 1998 Aladdin Enterprises.  All rights reserved.

<p>This file is part of Aladdin Ghostscript.  See the
<a href="Public.htm">Aladdin Free Public License</a> (the "License") for
full details of the terms of using, copying, modifying, and redistributing
Aladdin Ghostscript.

<p>
Ghostscript version 5.50, 16 September 1998

</font>

<!-- [3.0 end visible trailer] --------------------------------------------- -->

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -