Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Calling win32:api dll with pointer to array

by larryk (Friar)
on Jan 14, 2002 at 18:51 UTC ( #138574=note: print w/replies, xml ) Need Help??

in reply to Calling win32:api dll with pointer to array

From perldoc Win32::API:
The third parameter, the input parameter list, specifies how many arguments the function wants, and their types. It MUST be passed as a list reference. The following forms are valid: [a, b, c, d] \@LIST
so make up a reference to an anonymous list as:
my $arr = [ pack("d",1), pack("d",1.5), pack("d",3) ]; # or as I would do it... my $arr = [ map { pack 'd', $_ } ( 1, 1.5, 3 ) ];
The [] square brackets make an anonymous array so the scalar $arr (which you need to supply to the Call method of Win32::API) contains a reference to that array.

You could as easily do:

my @arr = map { pack 'd', $_ } ( 1, 1.5, 3 );
and then pass a reference to the list (\@arr) - whichever you prefer.

Hope this helps

perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

Replies are listed 'Best First'.
(tye)Re2: Calling win32:api dll with pointer to array
by tye (Sage) on Jan 14, 2002 at 19:41 UTC

    No, the documentation that you quote is talking about the third argument to the new() method, which certain shouldn't contain packed double values. It is talking about the argument [P, I] in the code above.

    The array of doubles is an argument to the C API being accessed and so gets passed in via the Call() method.

    Note that I avoid using the style found in the Win32::API documentation and would rewrite the code as:     my $obj= Win32::API->new( "dll", "Function", [qw( P I )], 'I' );
    so that I could use strict with it.

            - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://138574]
[Corion]: Do you have any specific interests or general Perl knowledge?
[Cosmic37]: should I slurp? should I grep? Noble Lords I wish you good karma and beg your advice
[Corion]: Cosmic37: Ah, see perlfaq4, about How do I compute the intersection of two arrays
[Cosmic37]: I am out of practice; I use Perl for scientific programming for number crunching
[Corion]: Cosmic37: Basically, you read one file into a hash, keyed by your key, and then match the lines from the second file to that hash
[Cosmic37]: note that the two files only have datetimes which may match whereas other data per line is different format in file1 and file2 - is that really intersection?
[jedikaiti]: Hi Monks
[Corion]: Cosmic37: Well, if you want to use only parts of a line for the key, see split or whatever other mechanism to extract the key from the line
[Corion]: Hi jedikaiti!
[Cosmic37]: is there a webpage for full CB for this chat rather than side panel chat?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-06-29 16:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.