Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Win32::API::Struct - Automatic pointer creation not working ?

by fx (Pilgrim)
on Jul 02, 2004 at 13:58 UTC ( [id://371394] : perlquestion . print w/replies, xml ) Need Help??

fx has asked for the wisdom of the Perl Monks concerning the following question:

The Win32::API::Struct v0.41 module documentation states the following:

Also note that typedef automatically defines an 'LPNAME' type, which holds a pointer to your structure.

Using the example in that documentation, I have created a POINT structure. This should mean that I have also automatically created an LPPOINT structure.

If this is the case, why does the following not work:

#!c:\perl\bin\perl -w use strict; use Data::Dumper; use Win32::API; Win32::API::Struct->typedef( 'POINT', 'LONG', 'x', 'LONG', 'y' ); my $point = Win32::API::Struct->new( 'LPPOINT' ) or die $!; print Dumper( $point );

with the error message being:

Unknown Win32::API::Struct 'LPPOINT' at C:\ line 9 Died at C:\ line 9, <DATA> line 164.

Is the documentation wrong or am I not reading it correctly?


fx, Infinity is Colourless

Replies are listed 'Best First'.
Re: Win32::API::Struct - Automatic pointer creation not working ?
by BrowserUk (Patriarch) on Jul 02, 2004 at 15:33 UTC

    LPPOINT is not a structure, it is a type.

    POINT is a structure, and LPPOINT is, long pointer to a POINT structure.

    You create a POINT structure, fill in the values, and then pass it to an api call that takes an LPPOINT as an argument. Under the covers, Win32::API obtains the address of the memory Perl allocates to hold the POINT structure and passes that to the api.

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

      I've had a look at the C function I am trying to call and althought it wants a pointer to struct, the variable name for this pointer to struct does not being LP - it's just called WORKITEMINFO.

      In my mind, therefore, the automatic pointer creation of Win32::API::Struct isn't going to help me.

      Does anyone have any suggestions as to how I should progress this - it's almost getting to the point where I might as well just write this in C! :)

      fx, Infinity is Colourless