----- Original Message -----
From: "Rogers, John" <[EMAIL PROTECTED]>
To: "'Perl-Win32-Users (E-mail)"
<[email protected]>
Sent: Thursday, April 21, 2005 2:26 PM
Subject: RE: Win32-API and ghostscript API
I got gsapi_ from the api.htm doc with gs8.15 gsdll_ is depreciated.
A dll export browser shows both though. I assume there the same, only
different format parameters
Cant make gsapi_ work though.
-------------------------------------
John,
Yep - found the gsapi_ stuff. By my reading of the Win32::API docs, the code
below should work ...... but it doesn't. All it does is print '0', followed
by "Use of uninitialized value in print at gsapi.pl line 19, <DATA> line
164." (four times).
use warnings;
use Win32::API;
Win32::API::Struct->typedef( gsapi_revision_t => qw{
char * product;
char * copyright;
long revision;
long revisiondate;
});
my $len = 16; # = sizeof(gsapi_revision_t) on Win32
Win32::API->Import('gsdll32', 'int gsapi_revision(gsapi_revision_t * pr, int
len)');
my $revobj = Win32::API::Struct->new('gsapi_revision_t');
my $ret = gsapi_revision($revobj, $len);
print $ret, "\n"; # Expect 0 if function call succeeds
print $revobj->{product}, "\n",
$revobj->{copyright}, "\n",
$revobj->{revision}, "\n",
$revobj->{revisiondate}, "\n";
__END__
I can't see why that doesn't work (at least wrt the two 'long' values),
given that the following code works fine:
use warnings;
use Win32::API;
Win32::API::Struct->typedef( gsapi_revision_t => qw{
LONG x;
LONG y;
});
Win32::API->Import('user32', 'BOOL GetCursorPos(gsapi_revision_t lpt)');
my $revobj = Win32::API::Struct->new('gsapi_revision_t');
GetCursorPos($revobj);
print "The cursor is at: ", $revobj->{x}, ", ", $revobj->{y}, "\n";
__END__
Maybe there's a problem with calling conventions used in constructing
gsdll32.dll.
My own preference for making this info available to perl would be to use
Inline::C - though I find I then have to link directly to gsdll32.dll -
which means that MS compilers are unusable - one has to use MinGW (gcc). For
some reason, linking to gsdll32.lib doesn't work (for me, anyway). I get an
error along the lines of "undefined reference to _gsapi_revision".
If you're interested, this works with MinGW compiler (but not MS compilers):
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1,
MYEXTLIB => 'D:/ghostscript/gsdll32.dll';
use Inline C => <<'EOC';
#include "gsdll32.h"
void print_revision_info() {
gsapi_revision_t r;
if (gsapi_revision(&r, sizeof(r)) == 0)
printf("\nPROD: %s\nCOPY: %s\nREV: %d\nDATE: %d\n",
r.product, r.copyright, r.revision, r.revisiondate);
else croak("Call to gsapi_revision in print_revision_info failed");
}
void return_revision_info() {
Inline_Stack_Vars;
gsapi_revision_t r;
Inline_Stack_Reset;
if (gsapi_revision(&r, sizeof(r)) == 0) {
Inline_Stack_Push(sv_2mortal(newSVpv(r.product, 0)));
Inline_Stack_Push(sv_2mortal(newSVpv(r.copyright, 0)));
Inline_Stack_Push(sv_2mortal(newSVuv(r.revision)));
Inline_Stack_Push(sv_2mortal(newSVuv(r.revisiondate)));
Inline_Stack_Done;
Inline_Stack_Return(4);
}
else croak("Call to gsapi_revision in return_revision_info failed");
}
EOC
# Start of perl code
print_revision_info();
($prod, $copy, $rev, $revdate) = return_revision_info();
print "\n\$prod: $prod\n",
"\$copy: $copy\n",
"\$rev: $rev\n",
"\$revdate: $revdate\n";
__END__
gsdll32.h (included in the above code) can be created from the ghostscript
docs info. For the purposes of the above it can simply be:
//---------------------
typedef struct gsapi_revision_s {
const char *product;
const char *copyright;
long revision;
long revisiondate;
} gsapi_revision_t;
int gsapi_revision (gsapi_revision_t *pr, int len);
//----------------------
Cheers,
Rob
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs