From: "Rogers, John" <[EMAIL PROTECTED]>
>
> Current state of play,
> can start instance and delete it. But cant exit or use it !
>
Took a while - but here 'tis (or at least *one* way of getting the job
done):
use warnings;
use Win32::API;
Win32::API::Struct->typedef( PINSTANCE => qw{
PVOID pinstance;
});
Win32::API->Import('gsdll32.dll', 'int gsapi_new_instance(PINSTANCE * pinst,
PVOID caller_handle)');
$pinst = Win32::API::Struct->new('PINSTANCE');
$caller_handle = "\0";
$gsargc = 10;
$gsargv = pack('pppppppppp', 'ps_to_pdf', '-dNOPAUSE', '-dBATCH', '-dSAFER',
'-sDEVICE=pdfwrite', '-sOutputFile=apiout.pdf', '-c', '.setpdfwrite', '-f',
'../examples/alphabet.ps');
$ret = gsapi_new_instance($pinst, $caller_handle);
print "new instance: $ret\n"; # success = 0
$rewrite = Win32::API->new('gsdll32.dll', 'gsapi_init_with_args', 'PNP',
'N');
if(not defined $rewrite) {die "Cannnot import gsapi_init_with_args(): $!\n"}
else {print "imported gsapi_init_with_args\n"}
$ret = $rewrite->Call($pinst->{pinstance}, $gsargc, $gsargv);
print "init_with_args: $ret\n"; # success = 0
$exit = Win32::API->new('gsdll32.dll', 'gsapi_exit', 'P', 'N');
if(not defined $exit) {die "Cannot import gsapi_new_instance(): $!\n"}
else {print "imported gsapi_exit\n"}
$ret = $exit->Call($pinst->{pinstance});
print "exit: $ret\n"; # success = 0
__END__
As I mentioned earlier, it relies on a lot of other ghostscript files -
mainly files in the 'lib' folder. If you place the above script in the lib
folder, place a copy of fonts/p052023l.pfb in the lib folder, then cd to the
lib folder, you should be able to run that script as is. It converts
examples/alphabet.ps to a pdf file named 'apiout.pdf' which gets created in
the current directory (at the expense of approx 9x bloat). If there's a
needed file that can't be found, it will be mentioned by name in the error
message.
Let me know if you have any trouble with it - also could you let me know if
you find you can run it successfully from outside the lib folder.
Beware of line-wraps when you copy'n'paste.
Interesting exercise :-)
Cheers,
Rob
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs