Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Win32::API

by dada (Chaplain)
on Jul 15, 2002 at 09:57 UTC ( #181728=note: print w/ replies, xml ) Need Help??

in reply to Win32::API

Guilderstern wrote:

There are two drawbacks to Win32::API that I've noticed so far. One could be easily remedied, while the other is probably not something I should hold my breath for...

hold your breath instead :-)
I'm working on a new release of Win32::API which will make your life a lot easier by supporting not only named types (eg. WORD, DWORD et al.) but structures too.

soon (I hope) you'll be able to say:

use Win32::API 0.40; Win32::API::Struct->typedef 'POINT', qw( LONG x LONG y ); Win32::API->Import( 'user32', 'BOOL GetCursorPos(LPPOINT lpPoint)' ); my $point = Win32::API::Struct->new('POINT'); my $retval = GetCursorPos($point); print "Cursor is at $point->{x}, $point->{y}\n";
...and callbacks will be there. I'm still cleaning things up, but I bet you'll be surprised :-)

oh, and BTW:

One example I'm thinking of is placing icons in the system tray. To be able to respond to mouse clicks, the function call that places the icon there must specify a callback that gets executed on a mouse click. AFAIK, there is no way to do this yet in Perl, and it may be impossible at the present.

well, there's Win32::GUI for this.


__END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;

Comment on Re: Win32::API
Select or Download Code
Replies are listed 'Best First'.
Re: Win32::API (finally)
by dada (Chaplain) on Mar 07, 2003 at 14:17 UTC
    as promised (and after a mere 6 months or so :-), I've released version 0.40 of Win32::API.

    it may not be on CPAN at the time I write, but here's the link to download it from my site:

    the synopsis I gave in my previous message still applies :-)

    there is even support for callbacks, but it is very experimental: feedback is appreciated as always.


    King of Laziness, Wizard of Impatience, Lord of Hubris

      Wow man, you must not really be the King of Laziness, cause this is awesome! I really appreciate your work.
      Very nice and Very handy package.
      I'm having a problem, however... :-)

      In short, I'm trying to use Win32::API to call CreateProcess.

      All is well except for the LPSTARTUPINFO and LPPROCESS_INFORMATION parms I pass into the call. If I create these using pack(...) for the correct number of bytes, it works fine and I can get the PID back out of the PROCESS_INFORMATION object (my ultimate goal).

      If, however, I create these parms using the Win32::API::Struct->new( 'STARTUPINFO' ) approach, the call fails. I'm even setting the .cb field to the size of the structure. The error I get back (using Win32::GetLastError()) is "Invalid access to memory location". Here's the function call I'm making (same in both cases):

      <-----------snip------------> # version 1 - succeeds my $si = pack( "L17", ((0) x 17) ); $si = pack( "LL16", length( $si ), ((0) x 16 ) ); my $pi = pack( "L4", ((0) x 4 ) ); # version 2 - fails my $si = Win32::API::Struct->new( "STARTUPINFO" ); $si->{cb} = $si->sizeof(); my $pi = Win32::API::Struct->new( "PROCESS_INFORMATION" ); my $retval = CreateProcess( "c:\\winnt\\notepad.exe", 0, # unused - cmdline ptr, unused 0, # unused - proc attributes ptr 0, # unused - thread attributes ptr 0, # unused - inherit handles 0, # unused - creation flags 0, # unused - env pointer 0, # unused - current dir ptr $si, $pi ); <-----------snip------------>
      Should CreateProcess be called the same way in both cases? When a ->new('STARTUPINFO') is called, is the memory zeroed-out upon creation? Any idea why the pack version succeeds and the Struct verion fails?

      D. Smith

        At least part of the problem is that Win32::API::Struct (or rather, Win32::API::Type) does have support for the STARTUPINFO structure, or at least not as of version 0.41 which is the latest version I can find.

        The fact that you aren't receiving the warnings I get:

        Unknown Win32::API::Struct 'STARTUPINFO' at - line 7 Can't call method "sizeof" on an undefined value at - line 8, <DATA> l +ine 164.

        means that either

        • you don't have warnings enabled.

          If so, turn them on, it'll save you much grief:)

        • You have a later version of the package than I have been able to find.

          If so, which version is it and where can I get a copy:)

        • You have a (locally?) modified copy of the package.

          If so, consult the people that made the modifications.

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://181728]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-10-14 03:07 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (320 votes), past polls