Trevor Walker wrote:
> Unfortunately, I do not have a C prototype for the DLL, or its source
> code... because it is written in Delphi (!!). The call used
> from Delphi is attached... it should give you an idea.
I can't really tell as I haven't had any experiencing interfacing Delphi or
Pascal with C or Perl. However, it looks as if the procedure takes two
arguments: a structure ("record" in Delphi parlance) and a pointer to a
structure ("record" passed as "var"). Furthermore, this record contains
single precision floating-point numbers.
So -- I don't know how to go further, but I think you need to find out at
least:
- what "stdcall" means as far as calling conventions are concerned
- how to pass a structure to a Delphi function by value and by reference
(does the whole structure really get pushed on the stack when you
call-by-value or does a pointer get pushed? If the latter, then both can
probably be simulated by packing the fields up in a string and using 'P' for
the prototype)
- how single-precision floating point numbers are represented in Delphi (if
the same as your C compiler's 'float' type, you should be able to use
pack('f', ...))
- how a string is represented in Delphi (I think it's (length, values)
rather than null-terminated as in C)
- how an integer is represented in Delphi (might by the same as C's integer,
might be different)
You'll also want to initialise the return buffer, similar to the way it's
done in the Delphi code. And since it's a procedure, not a function, in
Delphi, the return type is 'V' for void.
So, my *guess* is something like this:
#!perl -w
use strict;
use Win32::API;
my $library = "KrugerCall";
my $functionname = "FanSelFnName";
my @argumenttypes = ("P", "P");
my $returntype = "V";
my $fda = 'FDA';
my $MyIn =
chr(length($fda)) . $fda . # in fan type
pack('ff', 1.5, 200) . # air vol, pressure
pack('i', 1) . # pressure type
pack('fffff', 2.5, # additional vel heads
300, # max height
600, # max wide
900, # max len
1) . # num width dia
pack('i', 1) . # inlet vanes
pack('ff', 0, 40) . # temperature, altitude
pack('i10', 1, (0) x 9); # required extras
my $MyOut =
pack('i', 0) . # error code
scalar(chr(1) . ' ') x 50 . # fan name -- is this how to
# allocate an array of strings?
pack('i50', (0) x 50) . # fan type
pack('f50', (0) x 50) . # fan dia
... etc ... good luck especially with the arrays of arrays ... hope you
get the idea
;
$func = new Win32::API($library, $functionname, \@argumenttypes,
$returntype);
$func->Call($MyIn, $MyOut);
# now unpack $MyOut into its component parts with
# lots of 'unpack' ... oh joy....
Cheers,
Philip
Unit2.pas