DLL.htm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>How to use the Ghostscript Dynamic Link Library (DLL)</title>
  5. <!-- $Id: DLL.htm,v 1.15.2.2 2002/02/01 05:31:24 raph Exp $ -->
  6. <!-- Originally: dll.txt -->
  7. <link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
  8. </head>
  9. <body>
  10. <!-- [1.0 begin visible header] ============================================ -->
  11. <!-- [1.1 begin headline] ================================================== -->
  12. <h1>How to use the Ghostscript Dynamic Link Library (DLL)</h1>
  13. <!-- [1.1 end headline] ==================================================== -->
  14. <!-- [1.2 begin table of contents] ========================================= -->
  15. <h2>Table of contents</h2>
  16. <ul>
  17. <li><a href="#DLL">What is the Ghostscript DLL?</a>
  18. <li><a href="#Common_functions">Platform-independent DLL functions</a>
  19. <ul>
  20. <li><a href="#revision"><b><tt>gsdll_revision()</tt></b></a>
  21. <li><a href="#init"><b><tt>gsdll_init()</tt></b></a>
  22. <li><a href="#execute_begin"><b><tt>gsdll_execute_begin()</tt></b></a>
  23. <li><a href="#execute_cont"><b><tt>gsdll_execute_cont()</tt></b></a>
  24. <li><a href="#execute_end"><b><tt>gsdll_execute_end()</tt></b></a>
  25. <li><a href="#exit"><b><tt>gsdll_exit()</tt></b></a>
  26. <li><a href="#lock_device"><b><tt>gsdll_lock_device()</tt></b></a>
  27. </ul>
  28. <li><a href="#Callback">Callback function</a>
  29. <li><a href="#OS2_device">Ghostscript DLL device for OS/2</a>
  30. <ul>
  31. <li><a href="#OS2_bmp"><b><tt>gsdll_get_bitmap()</tt></b></a>
  32. <li><a href="#OS2_example">Example DLL usage for OS/2</a>
  33. </ul>
  34. <li><a href="#Win_device">Ghostscript DLL device for MS Windows</a>
  35. <ul>
  36. <li><a href="#Win_copydib"><b><tt>gsdll_copy_dib()</tt></b></a>
  37. <li><a href="#Win_copypalette"><b><tt>gsdll_copy_palette()</tt></b></a>
  38. <li><a href="#Win_draw"><b><tt>gsdll_draw()</tt></b></a>
  39. <li><a href="#Win_get_row"><b><tt>gsdll_get_bitmap_row()</tt></b></a>
  40. </ul>
  41. <li><a href="#Win16">Ghostscript DLL Device for 16-bit MS Windows</a>
  42. </ul>
  43. <!-- [1.2 end table of contents] =========================================== -->
  44. <!-- [1.3 begin hint] ====================================================== -->
  45. <p>For other information, see the <a href="Readme.htm">Ghostscript
  46. overview</a>.
  47. <p>
  48. <b>WARNING: The API described in this document is obsolete and will
  49. be removed in the future.</b>
  50. The current Ghostscript Interpreter API
  51. is described in <a href="API.htm">API.htm</a>.
  52. <!-- [1.3 end hint] ======================================================== -->
  53. <hr>
  54. <!-- [1.0 end visible header] ============================================== -->
  55. <!-- [2.0 begin contents] ================================================== -->
  56. <h2><a name="DLL"></a>What is the Ghostscript DLL?</h2>
  57. <p>
  58. For the OS/2, Win16 and Win32 platforms, Ghostscript is built as a dynamic
  59. link library (DLL), and to provide the interface described in the <a
  60. href="Use.htm">usage documentation</a>, a smaller independent executable
  61. (<b><tt>.EXE</tt></b>) loads this DLL, which provides all the interaction
  62. with the windowing system, including image windows and, if necessary, a
  63. text window. This document describes the DLL interface, which consists of
  64. eight main functions, <a href="#functions">seven platform-independent
  65. ones</a> provided by the DLL and one, <a href="#Callback">the callback
  66. function</a>, provided by the caller. The DLL provides some other
  67. platform-specific functions for display devices.
  68. <p>
  69. The DLL's name and characteristics differ among the three platforms:
  70. <ul>
  71. <li>The <a href="#OS2_device">OS/2 DLL <b><tt>GSDLL2.DLL</tt></b></a> has
  72. MULTIPLE NONSHARED data segments and can be called by multiple programs
  73. simultaneously.
  74. <li>The <a href="#Win_device">Win32 DLL <b><tt>GSDLL32.DLL</tt></b></a> has
  75. MULTIPLE NONSHARED data segments. Under Win32s it can be used by only one
  76. program at a time, but under Windows 95/98 or Windows NT it can be called by
  77. multiple programs simultaneously.
  78. <li>The <a href="#Win16">Win16 DLL <b><tt>GSDLL16.DLL</tt></b></a> is a
  79. large-memory model DLL with far static data. Due to the limitations of
  80. 16-bit MS Windows -- Windows 3.n -- the DLL can be used by only one program
  81. at a time.
  82. </ul>
  83. <p>
  84. The source for the executable is in <b><tt>dp</tt></b>*.* (OS/2) and
  85. <b><tt>dw</tt></b>*.* (Windows). See these source files for examples of
  86. how to use the DLL.
  87. <hr>
  88. <h2><a name="Common_functions"></a>Platform-independent DLL functions</h2>
  89. <p>
  90. The seven functions provided by the DLL are
  91. <ul>
  92. <li><b><tt>int GSDLLAPI <a href="#revision">gsdll_revision</a>(char **product, char **copyright, long *gs_revision, long *gs_revisiondate)</tt></b>
  93. <li><b><tt>int GSDLLAPI <a href="#init">gsdll_init</a>(GSDLL_CALLBACK callback, HWND hwnd, int argc, char *argv[]);</tt></b>
  94. <li><b><tt>int GSDLLAPI <a href="#execute_begin">gsdll_execute_begin</a>(void);</tt></b>
  95. <li><b><tt>int GSDLLAPI <a href="#execute_cont">gsdll_execute_cont</a>(const char *str, int len);</tt></b>
  96. <li><b><tt>int GSDLLAPI <a href="#execute_end">gsdll_execute_end</a>(void);</tt></b>
  97. <li><b><tt>int GSDLLAPI <a href="#exit">gsdll_exit</a>(void);</tt></b>
  98. <li><b><tt>int GSDLLAPI <a href="#lock_device">gsdll_lock_device</a>(unsigned char *device, int flag);</tt></b>
  99. <p>
  100. where <b><tt>GSDLLAPI</tt></b> is defined under OS/2 as
  101. <blockquote><b><tt>
  102. #define GSDLLAPI
  103. </tt></b></blockquote>
  104. <p>
  105. and under MS Windows as
  106. <blockquote><b><tt>
  107. #define GSDLLAPI CALLBACK _export
  108. </tt></b></blockquote>
  109. </ul>
  110. <h3><a name="revision"></a><b><tt>gsdll_revision()</tt></b></h3>
  111. <blockquote>
  112. This function returns the revision numbers and strings of the Ghostscript
  113. DLL; you should call it before <b><tt>gsdll_init()</tt></b> to make sure
  114. that the correct version of the Ghostscript DLL has been loaded. For
  115. example
  116. <blockquote>
  117. <pre>char *product;
  118. char *copyright;
  119. long revision;
  120. long revisiondate;
  121. gsdll_revision(&amp;product, &amp;copyright, &amp;revision, &amp;revisiondate);
  122. </pre></blockquote>
  123. <p>
  124. You may use <b><tt>NULL</tt></b> pointers if you do not want a particular
  125. value.
  126. </blockquote>
  127. <h3><a name="init"></a><b><tt>gsdll_init()</tt></b></h3>
  128. <blockquote>
  129. <b><tt>gsdll_init()</tt></b> must be called after loading the DLL and
  130. before executing any Ghostscript commands. The arguments are the address
  131. of the callback function, a parent window handle, the count of arguments
  132. and an array of pointers to the arguments. For example
  133. <blockquote>
  134. <pre>char *argv[5];
  135. argv[0] = "gswin.exe";
  136. argv[1] = "-Ic:\\gs;c:\gs\\fonts";
  137. argv[2] = "-dNOPAUSE",
  138. argv[3] = "-sDEVICE=djet500",
  139. argv[4] = NULL;
  140. argc = 4;
  141. code = gsdll_init(gsdll_callback, hwnd, argc, argv);
  142. </pre></blockquote>
  143. <p>
  144. <b><tt>hwnd</tt></b> is used as the parent window handle for any windows
  145. created by Ghostscript. <b><tt>hwnd</tt></b> may be <b><tt>NULL</tt></b>
  146. if the caller has no windows, but if it is <b><tt>NULL</tt></b>, you should
  147. avoid using devices which may open windows.
  148. <p>
  149. A return code of 0 (zero) indicates no errors, and the code may now call
  150. <b><tt>gsdll_execute_begin()</tt></b> or <b><tt>gsdll_exit()</tt></b>. If
  151. the return value is non-zero then <b><tt>gsdll_exit()</tt></b> must not be
  152. called.
  153. <p>
  154. A return value of <b><tt>GSDLL_INIT_QUIT</tt></b> indicates that one of the
  155. command line files or arguments called "<b><tt>quit</tt></b>", or that
  156. Ghostscript was reading stdin and reached end-of-file. This is not an
  157. error. <b><tt>gsdll_exit()</tt></b> must not be called.
  158. <p>
  159. A return value of <b><tt>GSDLL_INIT_IN_USE</tt></b> indicates that the DLL
  160. is in use by another application (Windows 3.1 only). The DLL should be
  161. immediately unloaded (or the caller terminated).
  162. <b><tt>gsdll_exit()</tt></b> must not be called.
  163. </blockquote>
  164. <h3><a name="execute_begin"></a><b><tt>gsdll_execute_begin()</tt></b></h3>
  165. <blockquote>
  166. This must be called after <b><tt>gsdll_init()</tt></b> and before
  167. <b><tt>gsdll_execute_cont()</tt></b>.
  168. </blockquote>
  169. <h3><a name="execute_cont"></a><b><tt>gsdll_execute_cont()</tt></b></h3>
  170. <blockquote>
  171. After successfully calling <b><tt>gsdll_init()</tt></b> and
  172. <b><tt>gsdll_execute_begin()</tt></b>, commands may be given to Ghostscript
  173. with <b><tt>gsdll_execute_cont()</tt></b>. Examples are:
  174. <blockquote>
  175. <pre>char *command = "1 2 add == flush\n";
  176. code = gsdll_execute_cont(command, strlen(command));
  177. command = "qu"
  178. code = gsdll_execute_cont(command, strlen(command));
  179. command = "it\n"
  180. code = gsdll_execute_cont(command, strlen(command));
  181. </pre>
  182. <a name="cont_returns"></a>
  183. <table cellpadding=0 cellspacing=0>
  184. <tr><th colspan=3 bgcolor="#CCCC00"><hr><font size="+1">Return codes from <b><tt>gsdll_execute_cont()</tt></b></font><hr>
  185. <tr valign=bottom>
  186. <th align=left>Code
  187. <td>&nbsp;&nbsp;&nbsp;&nbsp;
  188. <th align=left>Status
  189. <tr> <td colspan=3><hr>
  190. <tr valign=top> <td align=left>0
  191. <td>&nbsp;
  192. <td>No errors
  193. <tr valign=top> <td align=left>&lt; 0
  194. <td>&nbsp;
  195. <td>Error
  196. <tr valign=top> <td align=left>&lt;= -100
  197. <td>&nbsp;
  198. <td>"<b><tt>quit</tt></b>" has been executed, or fatal error.
  199. <b><tt>gsdll_exit()</tt></b> must then be called: do not call
  200. <b><tt>gsdll_execute_end()</tt></b>.
  201. </table>
  202. </blockquote>
  203. <b><tt>gsdll_execute_cont()</tt></b>
  204. does not flush stdio, so if you want to see output from Ghostscript you
  205. must do this explicitly as shown in the example above.
  206. <p>
  207. When executing a string with <b><tt>gsdll_execute_cont()</tt></b>,
  208. <b><tt>currentfile</tt></b> is the input from
  209. <b><tt>gsdll_execute_cont()</tt></b>. Reading from <b><tt>%stdin</tt></b>
  210. uses the callback.
  211. </blockquote>
  212. <h3><a name="execute_end"></a><b><tt>gsdll_execute_end()</tt></b></h3>
  213. <blockquote>
  214. If <b><tt>gsdll_execute_cont()</tt></b> did not return an error, then
  215. <b><tt>gsdll_execute_end()</tt></b> must be called after
  216. <b><tt>gsdll_execute_cont()</tt></b> and before
  217. <b><tt>gsdll_exit()</tt></b>.
  218. </blockquote>
  219. <h3><a name="exit"></a><b><tt>gsdll_exit()</tt></b></h3>
  220. <blockquote>
  221. Call gsdll_exit() to terminate the Ghostscript DLL. It must be called if a
  222. fatal error has occurred; see the <a href="#cont_returns">return value
  223. of <b><tt>gsdll_execute_cont()</tt></b></a>. After calling
  224. <b><tt>gsdll_exit()</tt></b>, there are two options:
  225. <ul>
  226. <li>Unload the DLL, either by terminating the application or by
  227. calling <b><tt>DosFreeModule</tt></b> (OS/2) or <b><tt>FreeLibrary</tt></b> (MS Windows).
  228. <li>Call <b><tt>gsdll_init()</tt></b> again to restart Ghostscript.
  229. </ul>
  230. </blockquote>
  231. <h3><a name="lock_device"></a><b><tt>gsdll_lock_device()</tt></b></h3>
  232. <blockquote>
  233. Since the caller may be multithreaded, a lock is needed to control access
  234. to the display device, and <b><tt>gsdll_lock_device()</tt></b> provides that
  235. locking.
  236. <blockquote>
  237. <pre>int gsdll_lock_device(unsigned char *device, int flag);
  238. /* Lock the device if flag = TRUE */
  239. /* Unlock the device if flag = FALSE */
  240. /* device is a pointer to Ghostscript os2dll or mswindll device */
  241. /* from GSDLL_DEVICE message. */
  242. /* Return value is the lock count. */
  243. </pre>
  244. <table cellpadding=0 cellspacing=0>
  245. <tr><th colspan=3 bgcolor="#CCCC00"><hr><font size="+1">Locking and unlocking devices</font><hr>
  246. <tr valign=top> <td>To lock a device
  247. <td>&nbsp;&nbsp;&nbsp;&nbsp;
  248. <td><b><tt>gsdll_lock_device(device, 1)</tt></b>;
  249. <tr valign=top> <td>To unlock a device
  250. <td>&nbsp;
  251. <td><b><tt>gsdll_lock_device(device, 0)</tt></b>;
  252. </table>
  253. </blockquote>
  254. <p>
  255. This function is typically used to lock the device while repainting a
  256. window or copying the device bitmap to the clipboard. Ghostscript may draw
  257. into the device bitmap or update the palette entries while the device is
  258. locked by the caller, but locking the device prevents the Ghostscript DLL
  259. from closing the device or changing its size or depth.
  260. <p>
  261. Under OS/2, Windows 95/98 and Windows NT, this lock is implemented using a
  262. mutual exclusion semaphore (mutex). The return value is the lock count,
  263. which is either 0 ("unlocked") or 1 ("locked"). The function blocks until
  264. the device is locked by the caller.
  265. <p>
  266. Under Win16 or Win32s, <b><tt>gsdll_lock_device()</tt></b> always returns
  267. immediately with a lock count as its return value. A lock count of 2 or
  268. more is definite indication of an error, probably calling the function
  269. twice. Access to the device should be controlled by checking the Windows
  270. message queue only when the bitmap is not being accessed.
  271. </blockquote>
  272. <hr>
  273. <h2><a name="Callback"></a>Callback function</h2>
  274. <blockquote>
  275. As an argument to <a href="#init"><b><tt>gsdll_init()</tt></b></a> the
  276. caller must provide a callback function which the DLL invokes for stdio and
  277. to notify the caller about device events. The function provided by the
  278. caller has this prototype:
  279. <blockquote><b><tt>
  280. int gsdll_callback(int&nbsp;message, char&nbsp;*str, unsigned&nbsp;long&nbsp;count);
  281. </tt></b></blockquote>
  282. <p>
  283. The Pascal calling convention is not used. An example callback function
  284. is:
  285. <blockquote>
  286. <pre>int
  287. gsdll_callback(int message, char *str, unsigned long count)
  288. {
  289. char *p;
  290. switch (message) {
  291. case GSDLL_STDIN:
  292. p = fgets(str, count, stdin);
  293. if (p)
  294. return strlen(str);
  295. else
  296. return 0;
  297. case GSDLL_STDOUT:
  298. if (str != (char *)NULL)
  299. fwrite(str, 1, count, stdout);
  300. return count;
  301. case GSDLL_DEVICE:
  302. fprintf(stdout,"Callback: DEVICE %p %s\n", str,
  303. count ? "open" : "close");
  304. break;
  305. case GSDLL_SYNC:
  306. fprintf(stdout,"Callback: SYNC %p\n", str);
  307. break;
  308. case GSDLL_PAGE:
  309. fprintf(stdout,"Callback: PAGE %p\n", str);
  310. break;
  311. case GSDLL_SIZE:
  312. fprintf(stdout,"Callback: SIZE %p width=%d height=%d\n", str,
  313. (int)(count &amp; 0xffff), (int)((count&gt;&gt;16) &amp; 0xffff) );
  314. break;
  315. case GSDLL_POLL:
  316. return 0; /* no error */
  317. default:
  318. fprintf(stdout,"Callback: Unknown message=%d\n",message);
  319. break;
  320. }
  321. return 0;
  322. }
  323. </pre>
  324. <table cellpadding=0 cellspacing=0>
  325. <tr><th colspan=5 bgcolor="#CCCC00"><hr><font size="+1">Messages used by callback</font><hr>
  326. <tr valign=bottom>
  327. <th align=left>Symbol
  328. <td>&nbsp;&nbsp;
  329. <th align=left>
  330. <td>&nbsp;&nbsp;
  331. <th align=left>Use
  332. <tr> <td colspan=5><hr>
  333. <tr valign=top> <td><b><tt>GSDLL_STDIN</tt></b>
  334. <td>&nbsp;
  335. <td>1
  336. <td>&nbsp;
  337. <td>get <b><tt>count</tt></b> characters to <b><tt>str</tt></b> from stdin, return number of characters read
  338. <tr valign=top> <td><b><tt>GSDLL_STDOUT</tt></b>
  339. <td>&nbsp;
  340. <td>2
  341. <td>&nbsp;
  342. <td>put <b><tt>count</tt></b> characters from <b><tt>str</tt></b>
  343. to stdout, return number of characters written
  344. <tr valign=top> <td><b><tt>GSDLL_DEVICE</tt></b>
  345. <td>&nbsp;
  346. <td>3
  347. <td>&nbsp;
  348. <td>device <b><tt>str</tt></b> has been opened if
  349. <b><tt>count</tt></b>&nbsp;=&nbsp;1, closed if
  350. <b><tt>count</tt></b>&nbsp;=&nbsp;0
  351. <tr valign=top> <td><b><tt>GSDLL_SYNC</tt></b>
  352. <td>&nbsp;
  353. <td>4
  354. <td>&nbsp;
  355. <td>sync_output for device <b><tt>str</tt></b>
  356. <tr valign=top> <td><b><tt>GSDLL_PAGE</tt></b>
  357. <td>&nbsp;
  358. <td>5
  359. <td>&nbsp;
  360. <td>output_page for device <b><tt>str</tt></b>
  361. <tr valign=top> <td><b><tt>GSDLL_SIZE</tt></b>
  362. <td>&nbsp;
  363. <td>6
  364. <td>&nbsp;
  365. <td>resize for device <b><tt>str</tt></b>:
  366. LOWORD(<b><tt>count</tt></b>) is new <b><tt>xsize</tt></b>,
  367. HIWORD(<b><tt>count</tt></b>) is new <b><tt>ysize</tt></b>
  368. <tr valign=top> <td><b><tt>GSDLL_POLL</tt></b>
  369. <td>&nbsp;
  370. <td>7
  371. <td>&nbsp;
  372. <td>Called from <b><tt>gp_check_interrupt()</tt></b><br>
  373. Can be used by the caller to poll the message queue.
  374. Normally returns 0. To abort
  375. <b><tt>gsdll_execute_cont()</tt></b>, return a non-zero
  376. error code until <b><tt>gsdll_execute_cont()</tt></b>
  377. returns.
  378. </table>
  379. </blockquote>
  380. </blockquote>
  381. <hr>
  382. <h2><a name="OS2_device"></a>Ghostscript DLL device for OS/2</h2>
  383. <p>
  384. The <b><tt>os2dll</tt></b> device is provided in the Ghostscript DLL for
  385. use by the caller. No drawing facilities are provided by the DLL because
  386. the DLL may be loaded by a text-only (non-PM) application. The caller is
  387. notified via the <b><tt>gsdll_callback()</tt></b> when a new
  388. <b><tt>os2dll</tt></b> device is opened or closed
  389. (<b><tt>GSDLL_DEVICE</tt></b>), when the window should be redrawn
  390. (<b><tt>GSDLL_SYNC</tt></b> or <b><tt>GSDLL_PAGE</tt></b>) or when the
  391. bitmap size changes (<b><tt>GSDLL_SIZE</tt></b>).
  392. Note that more than one <b><tt>os2dll</tt></b> device may be opened.
  393. <h3><a name="OS2_bmp"></a><b><tt>gsdll_get_bitmap()</tt></b></h3>
  394. <blockquote>
  395. <b><tt>gsdll_get_bitmap()</tt></b> returns a pointer to a bitmap in BMP
  396. format. The <b><tt>os2dll</tt></b> device draws into this bitmap.
  397. <blockquote>
  398. <pre>unsigned long gsdll_get_bitmap(unsigned char *device, unsigned char **pbitmap);
  399. /* return in pbitmap the address of the bitmap */
  400. /* device is a pointer to Ghostscript os2dll device from GSDLL_DEVICE message */
  401. </pre></blockquote>
  402. <p>
  403. The caller can then display the bitmap however it likes, but should lock
  404. the bitmap with <b><tt>gsdll_lock_device()</tt></b> before painting from
  405. it, and unlock it afterwards. The bitmap address does not change until the
  406. <b><tt>os2dll</tt></b> device is closed; however the bitmap size and
  407. palette may change whenever the bitmap is not locked.
  408. </blockquote>
  409. <h3><a name="OS2_example"></a>Example DLL usage for OS/2</h3>
  410. <p>
  411. The example here shows a minimal usage of the Ghostscript DLL under OS/2.
  412. The sample callback function above is needed.
  413. <blockquote>
  414. <pre>#define INCL_DOS
  415. #include &lt;os2.h&gt;
  416. #include &lt;stdio.h&gt;
  417. #include "gsdll.h"
  418. PFN_gsdll_init pgsdll_init;
  419. PFN_gsdll_execute_begin pgsdll_execute_begin;
  420. PFN_gsdll_execute_cont pgsdll_execute_cont;
  421. PFN_gsdll_execute_end pgsdll_execute_end;
  422. PFN_gsdll_exit pgsdll_exit;
  423. HMODULE hmodule_gsdll;
  424. char buf[256];
  425. int
  426. main(int argc, char *argv[])
  427. {
  428. int code;
  429. APIRET rc;
  430. if (!DosLoadModule(buf, sizeof(buf), "GSDLL2", &amp;hmodule_gsdll)) {
  431. fprintf(stderr, "Loaded GSDLL2\n");
  432. DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_init", (PFN *)(&amp;pgsdll_init));
  433. DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_begin", (PFN *)(&amp;pgsdll_execute_begin));
  434. DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_cont", (PFN *)(&amp;pgsdll_execute_cont));
  435. DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_execute_end", (PFN *)(&amp;pgsdll_execute_end));
  436. DosQueryProcAddr(hmodule_gsdll, 0, "gsdll_exit", (PFN *)(&amp;pgsdll_exit));
  437. }
  438. else {
  439. fprintf(stderr, "Can't load GSDLL2\n");
  440. }
  441. code = (*pgsdll_init)(gsdll_callback, NULL, argc, argv);
  442. fprintf(stdout,"gsdll_init returns %d\n", code);
  443. code = (*pgsdll_execute_begin)();
  444. if (code==0) {
  445. while (fgets(buf, sizeof(buf), stdin)) {
  446. code = (*pgsdll_execute_cont)(buf, strlen(buf));
  447. fprintf(stdout,"gsdll_execute returns %d\n", code);
  448. if (code &lt; 0)
  449. break;
  450. }
  451. if (!code)
  452. code = (*pgsdll_execute_end)();
  453. code = (*pgsdll_exit)();
  454. fprintf(stdout,"gsdll_exit returns %d\n", code);
  455. }
  456. rc = DosFreeModule(hmodule_gsdll);
  457. fprintf(stdout,"DosFreeModule returns %d\n", rc);
  458. return 0;
  459. }
  460. </pre></blockquote>
  461. <hr>
  462. <h2><a name="Win_device"></a>Ghostscript DLL device for MS Windows</h2>
  463. <p>
  464. The <b><tt>mswindll</tt></b> device is provided in the Ghostscript DLL for
  465. use by the caller. The caller is notified via the
  466. <b><tt>gsdll_callback()</tt></b> when a new <b><tt>mswindll</tt></b> device
  467. is opened or closed (<b><tt>GSDLL_DEVICE</tt></b>), when the window should
  468. be redrawn (<b><tt>GSDLL_SYNC</tt></b> or <b><tt>GSDLL_PAGE</tt></b>) or
  469. when the bitmap size changes (<b><tt>GSDLL_SIZE</tt></b>). Note that more
  470. than one <b><tt>mswindll</tt></b> device may be opened.
  471. <p>
  472. Four DLL functions are available to use the <b><tt>mswindll</tt></b>
  473. device.
  474. <h3><a name="Win_copydib"></a><b><tt>gsdll_copy_dib()</tt></b></h3>
  475. <blockquote>
  476. Copy the <b><tt>mswindll</tt></b> bitmap to the clipboard.
  477. <blockquote>
  478. <pre>HGLOBAL GSDLLAPI gsdll_copy_dib(unsigned char *device);
  479. /* make a copy of the device bitmap and return shared memory handle to it */
  480. /* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
  481. </pre></blockquote>
  482. </blockquote>
  483. <h3><a name="Win_copypalette"></a><b><tt>gsdll_copy_palette()</tt></b></h3>
  484. <blockquote>
  485. Copy the <b><tt>mswindll</tt></b> palette to the clipboard.
  486. <blockquote>
  487. <pre>HPALETTE GSDLLAPI gsdll_copy_palette(unsigned char *device);
  488. /* make a copy of the device palette and return a handle to it */
  489. /* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
  490. </pre></blockquote>
  491. </blockquote>
  492. <h3><a name="Win_draw"></a><b><tt>gsdll_draw()</tt></b></h3>
  493. <blockquote>
  494. Display output from the <b><tt>mswindll</tt></b> device. The caller should
  495. create a window and call <b><tt>gsdll_draw()</tt></b> in response to the
  496. <b><tt>WM_PAINT</tt></b> message. The device context <b><tt>hdc</tt></b>
  497. must be for a device because <b><tt>SetDIBitsToDevice()</tt></b> is used.
  498. <blockquote>
  499. <pre>void GSDLLAPI gsdll_draw(unsigned char *device, HDC hdc,
  500. LPRECT dest, LPRECT src);
  501. /* copy the rectangle src from the device bitmap */
  502. /* to the rectangle dest on the device given by hdc */
  503. /* hdc must be a device context for a device (NOT a bitmap) */
  504. /* device is a pointer to Ghostscript device from GSDLL_DEVICE message */
  505. </pre></blockquote>
  506. </blockquote>
  507. <h3><a name="Win_get_row"></a><b><tt>gsdll_get_bitmap_row()</tt></b></h3>
  508. <blockquote>
  509. Get a BMP header, a palette, and a pointer to a row in the bitmap. This
  510. function exists to allow the bitmap to be copied to a file or structured
  511. storage without the overhead of having two copies of the bitmap in memory
  512. at the same time.
  513. <p>
  514. Ghostscript can change the palette while the device is locked. Do not call
  515. this function while Ghostscript is busy.
  516. <blockquote>
  517. <pre>int GSDLLAPI gsdll_get_bitmap_row(unsigned char *device, LPBITMAPINFOHEADER pbmih,
  518. LPRGBQUAD prgbquad, LPBYTE *ppbyte, unsigned int row)
  519. /* If pbmih nonzero, copy the BITMAPINFOHEADER.
  520. * If prgbquad nonzero, copy the palette.
  521. * number of entries copied is given by pbmih-&gt;biClrUsed
  522. * If ppbyte nonzero, return pointer to row.
  523. * pointer is only valid while device is locked
  524. */
  525. </pre></blockquote>
  526. </blockquote>
  527. <hr>
  528. <h2><a name="Win16"></a>Ghostscript DLL Device for 16-bit MS Windows</h2>
  529. <p>
  530. This platform has the most problems of the three. Support for it may be
  531. dropped in future.
  532. <p>
  533. The Win16 DLL <b><tt>GSDLL16.DLL</tt></b> is a large-memory model DLL with
  534. far static data. Due to the limitations of 16-bit MS Windows, the DLL can
  535. be used by only one program at a time.
  536. <p>
  537. However, <b><tt>GSDLL16</tt></b> is marked as having SINGLE SHARED data
  538. segments, allowing multiple applications to load it with no error
  539. indication. (The DLL wouldn't load at all if MULTIPLE NONSHARED was used).
  540. Nonetheless, <b>it cannot be used by more than one application at a
  541. time</b>, so applications loading <b><tt>GSDLL16</tt></b> should check the
  542. return value of <b><tt>gsdll_init()</tt></b>: if this value is non-zero,
  543. then <b><tt>GSDLL16</tt></b> is already in use by another application and
  544. should <b><em>not</em></b> be used: <b><tt>GSDLL16</tt></b> should be
  545. unloaded immediately using <b><tt>FreeLibrary()</tt></b>, or the calling
  546. program should quit without attempting to use the library..
  547. <p>
  548. The segmented architecture of the Intel 80286 causes the usual amount of
  549. grief when using <b><tt>GSDLL16</tt></b>. Because the callback is called
  550. from the DLL, which is using a different data segment, the callback must be
  551. declared as <b><tt>_far&nbsp;_export</tt></b>:
  552. <blockquote>
  553. <pre>int _far _export gsdll_callback(int message, char *str, unsigned long count);
  554. </pre></blockquote>
  555. <p>
  556. Instead of giving <b><tt>gsdll_init()</tt></b> the address of
  557. <b><tt>gsdll_callback()</tt></b>, it should instead be given the address of
  558. a thunk created by <b><tt>MakeProcInstance</tt></b>. This thunk changes
  559. the data segment back to that used by the caller:
  560. <blockquote>
  561. <pre>FARPROC lpfnCallback;
  562. lpfnCallback = (FARPROC)MakeProcInstance((FARPROC)gsdll_callback, hInstance);
  563. code = (*pgsdll_init)((GSDLL_CALLBACK)lpfnCallback, NULL, argc, argv);
  564. if (!code) {
  565. fprintf(stderr, "GSDLL16 is already in use\n");
  566. return -1;
  567. }
  568. </pre></blockquote>
  569. <!-- [2.0 end contents] ==================================================== -->
  570. <!-- [3.0 begin visible trailer] =========================================== -->
  571. <hr>
  572. <p>
  573. <small>Copyright &copy; 1996, 1997, 1998 Aladdin Enterprises.
  574. All rights reserved.</small>
  575. <p>
  576. <small>This file is part of AFPL Ghostscript. See the
  577. <a href="Public.htm">Aladdin Free Public License</a> (the "License") for
  578. full details of the terms of using, copying, modifying, and redistributing
  579. AFPL Ghostscript.</small>
  580. <p>
  581. <small>Ghostscript version 7.04, 31 January 2002
  582. <!-- [3.0 end visible trailer] ============================================= -->
  583. </body>
  584. </html>