GSWin DLL 
Author Message
 GSWin DLL

I am having a bit of a problem calling the GSWIN32.DLL.  I have written a
dll which is callable by any windows 32 bit application to perform a
postscript conversion. The first time it's run it works perfectly,but the
second iteration causes an error message saying,

"Already Initialized".

It then terminates the application with an application exception error.

I used DWMAINC.CPP as the core for the dll and basically just added one
function call for external apps to call.I have posted the code below:

You should note that I have coded the dcxmono device, but the code behaves
the same with pcx devices used.

#define STRICT
#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
extern "C" {
#include "gscdefs.h"
#define GSREVISION 510
#include "gsdll.h"

Quote:
}

#include "dwmain.h"
#include "dwdll.h"

#define _export

/* public handles */
HINSTANCE ghInstance;

const char *szDllName = "GSDLL32.DLL";

int FAR _export gsdll_callback(int message, char FAR *str, unsigned long
count);

// the Ghostscript DLL class
gsdll_class gsdll;

char start_string[] = "systemdict /start get exec\n";

// program really starts at WinMain
int
new_main(int argc, char *argv[])
{
typedef char FAR * FARARGV_PTR;
int rc;

    // load DLL
    if (gsdll.load(ghInstance, szDllName, GSREVISION)) {
 char buf[256];
 gsdll.get_last_error(buf, sizeof(buf));
 //fputs(buf, stdout);
 MessageBox(NULL,buf,"GS Message",0);
 return 1;
    }else{

  MessageBox(NULL,"Loaded OK","GS",0);
 }

    // initialize the interpreter
    rc = gsdll.init(gsdll_callback, (HWND)NULL, argc, argv);
    if (rc == GSDLL_INIT_QUIT) {
        gsdll.unload();
 return 0;
    }
    if (rc) {
 char buf[256];
 gsdll.get_last_error(buf, sizeof(buf));
 //fputs(buf, stdout);
 MessageBox(NULL,buf,"GS",0);
        gsdll.unload();
  return rc;
    }

    // if (!batch)
    gsdll.execute(start_string, strlen(start_string));
//    gsdll.exit(); //end the process
    gsdll.unload();

    return 0;

Quote:
}

BOOL APIENTRY DllMain( HANDLE hModule,
                        DWORD ul_reason_for_call,
                        LPVOID lpReserved )
{
    switch( ul_reason_for_call ) {
    case DLL_PROCESS_ATTACH:
  ghInstance = GetModuleHandle(NULL);
  break;
    //case DLL_THREAD_ATTACH:

    //case DLL_THREAD_DETACH:

    case DLL_PROCESS_DETACH:
 break;

    }
    return TRUE;

Quote:
}

__declspec(dllexport) int  VBtest(LPSTR psfilename,LPSTR dcxfilename){

 int argc;
 char *argv[10];
 char temp[255];

 argc=0;
 argv[argc++]="GSWIN32.EXE";
 argv[argc++]="-sDEVICE=dcxmono";
 strcpy(temp,"-sOutputFile=");
 strcat(temp,dcxfilename);
 argv[argc++]="-sOutputFile=pages.dcx";
 argv[argc++]="-dNOPAUSE";
 argv[argc++]="-r196x196";
 strcpy(temp,psfilename);
 argv[argc++]=temp;
 argv[argc]="quit.ps";

 //MessageBox(NULL,dcxfilename,psfilename,0);

return new_main(argc, argv);

Quote:
}

int
read_stdin(char FAR *str, int len)
{
int ch;
int count = 0;
    while (count < len) {
 ch = fgetc(stdin);
 if (ch == EOF)
     return count;
 *str++ = ch;
 count++;
 if (ch == '\n')
     return count;
    }
    return count;

Quote:
}

int FAR _export
gsdll_callback(int message, char FAR *str, unsigned long count)
{
char buf[256];
    switch (message) {
 case GSDLL_POLL:
     // Don't check message queue because we don't
     // create any windows.
     // May want to return error code if abort wanted
     break;
 case GSDLL_STDIN:
     return read_stdin(str, count);
 case GSDLL_STDOUT:
     //fwrite(str, 1, count, stdout);
     //fflush(stdout);
  MessageBox(NULL,str,"GS_STDOUT",0);
     return count;
 case GSDLL_DEVICE:
     if (count) {
  MessageBox(NULL,"mswindll device not supported by the commandine ",
"GS",0);
     }
     break;
 case GSDLL_SYNC:
     break;
 case GSDLL_PAGE:
     break;
 case GSDLL_SIZE:
     break;
 default:
     sprintf(buf,"Callback: Unknown message=%d\n",message);
     //fputs(buf, stdout);
  MessageBox(NULL,buf,"GS",0);
     break;
    }
    return 0;
Quote:
}



Sun, 29 Oct 2000 03:00:00 GMT  
 GSWin DLL



Quote:
> I am having a bit of a problem calling the GSWIN32.DLL.  I have written a
> dll which is callable by any windows 32 bit application to perform a
> postScript conversion. The first time it's run it works perfectly,but the
> second iteration causes an error message saying,

> "Already Initialized".

The Ghostscript DLL has some global static variables which restrict
you to calling it only once from your application.
This restriction will hopefully be relaxed in the next version of
Ghostscript, but it will require some changes to the DLL API.

The only way at the moment to call multiple copies of the DLL is
to load it from multiple applications.

This is the reason why GSview starts a separate program when
printing, instead of starting a separate thread with a new instance
of the DLL.

--
Russell Lang

(This is an email alias - I am not an employee or an agent of Aladdin
Enterprises)



Fri, 03 Nov 2000 03:00:00 GMT  
 GSWin DLL

Quote:

>> "Already Initialized".

>The Ghostscript DLL has some global static variables which restrict
>you to calling it only once from your application.
>This restriction will hopefully be relaxed in the next version of
>Ghostscript, but it will require some changes to the DLL API.

>The only way at the moment to call multiple copies of the DLL is
>to load it from multiple applications.

>This is the reason why GSview starts a separate program when
>printing, instead of starting a separate thread with a new instance
>of the DLL.

Thanks Russell, Looking at the code it seems to be "unloading" ghostscript
at the end. Does this mean it's not really being unloaded until my calling
DLL is removed from memory.

john



Fri, 03 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. GSwin.dll gswin32.dll

2. GSWin DLL

3. gswin

4. GSWin 3.12 Problems

5. Printing Problem with gswin 3.53

6. gswin - don't show the main window

7. PS => AI with GSWIN

8. GSVIEW & GSWIN for MS-Windows

9. gswin -? didn't work

10. To BJ-200 Using GSwin

11. GSWin 3.55

12. GSWIN 3.51 "quiet"

 

 
Powered by phpBB® Forum Software