[gs-bugs] Access Violation when calling gsapi_init_with_args

Martin Weber martin.weber at asbion.de
Thu May 27 09:18:51 UTC 2010


Hello,

i try to use the GhostScript gsdll32.dll with Delphi to create PDF files out 
of PostScript files.
The problem is, when i call gsapi_init_with_args, i get an access violation 
on address 00000000.

First InitialisePS2PDFConversion is called, and that calls gsInit, where 
gsapi_init_with_args is called.
There i get the access violation, i also tried @Arguments, but doesn't work 
either.
I have absolutely no idea what goes wrong here.

I work with gsapi 8.71 on Windows Vista 32-Bit.
IDE is Delphi 2005 Professional.

Here some code:


procedure TGhostScript.InitialisePS2PDFConversion(const APSFileName: 
TFileName);
var
  Argv: PPChar;
begin
  if Trim(APSFileName) = '' then
    raise Exception.Create(sNoInputFileSet);


  SetLength(Argv, 10);
 // Argv[0] := 
PAnsiChar(StringReplace(ParamStr(0),'\','\\',[rfReplaceAll]));
//I tried some things here, but has no effects
  Argv[0] := '-q';
  Argv[1] := '-dSAFER';
  Argv[2] := '-dNOPAUSE';
  Argv[3] := '-dBATCH';
  Argv[4] := PAnsiChar('-sOutputFile=' + 
ChangeFileExt(StringReplace(APSFileName,'\','\\',[rfReplaceAll]), '.PDF'));
  Argv[5] := '-sDEVICE=pdfwrite';
  Argv[6] := '-c';
  Argv[7] := '.setpdfwrite';
  Argv[8] := '-f';
  Argv[9] := PAnsiChar(StringReplace(APSFileName,'\','\\',[rfReplaceAll]));
  //
  gsInit(Argv);
end;

// Initializes the instance with arguments derived from the properties
procedure TGhostScript.gsInit(var Arguments: PPChar);
var
  Code: Integer;
begin
  if Length(Arguments) = 0 then
  begin
    SetLength(Arguments, 4);
    Arguments[0] := PAnsiChar(ParamStr(0));
    Arguments[1] := '-sDEVICE=display';  // display device
    Arguments[2] := PAnsiChar(GetDisplayFormatString);  // display format
    Arguments[3] := PAnsiChar('-r' + IntToStr(FResolution)); // resolution
  end;
  //
  try
    Code := gsapi_init_with_args(FInstance, Length(Arguments), Arguments);
  except on E: Exception do
    begin
      Code:=GetLastError;
      raise EGhostScriptInitException.CreateFmt(sInitFailed + #13 + 
E.Message+#13+SysErrorMessage(Code),[Code]);
    end;
  end;
  SetLength(Arguments, 0);
  if Code <= -100 then
  begin
    gsExit;
    raise EGhostScriptInitException.CreateFmt(sInitFailed, [Code]);
  end
  else if Code < 0 then
    raise EGhostScriptInitException.CreateFmt(sInitFailed, [Code])
  else FStatus := gsInitialised;
end;


It would be really great if somebody could help me here :)

Regards

Martin 



More information about the gs-bugs mailing list