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

Hello,

I'm trying to write an application that benchmarks the time it takes to fully load WinMe's helpctr.exe program (Help and Support Center). I'm having a bit of trouble getting my mind around setting windows hooks using the Win32::API perl library. Also, confused as to the best way one would determine which "handle to application instance" I should pass SetWindowsHookEx. Would I need to determine which DLL's helpctr.exe uses? Can one get this from knowing the window handle for helpctr?

use Win32::API; use strict; # # Omitted code: # (1) start the helpctr.exe process # (2) create time 0 benchmark object # # SetWindowsHookEx prototype info - # HHOOK SetWindowsHookEx ( # int idHook, // hook type # HOOKPROC lpfn, // hook procedure # HINSTANCE hMod, // handle to application instance # DWORD dwThreadId // thread identifier # ); # use constant WH_CALLWNDPROCRET => 12; my $SetWindowsHookEx = new Win32::API( "user32", "SetWindowsHookEx", [qw(I P N N)], 'N'); # how to determine hInstance(s) of helpctr for the following call? my $Hook = $SetWindowsHookEx->Call( WH_CALLWNDPROCRET, 'CallWndRetProc', $hInstance, 0); </b> Am I right in thinking that the best way to determine the state of the window is to evaluate all the return values of the message processed by that window? Thanks much. Marshall Random thot - it would be really cool if this site used something like the GURPs system for tracking the monastic ascension of users - something like the character development in the PC game "Fallout".

Replies are listed 'Best First'.
(tye)Re: Inspecting messages using Win32::API
by tye (Sage) on Feb 16, 2001 at 09:38 UTC

    This is called a "call back" and you can't do it with Win32::API. Go grab the FFI.pm module (and yell at ActiveState and/or IndigoStar if they still don't have a binary version of this module for you).

    The second argument would need to be of type "N", not "P" (Win32::API's "P" is mostly only useful for '\0'-terminated strings), and would need to be the address of a C subroutine (well, it could be a subroutine in any number of languages provided that it follows the appropriate Win32 calling conventions, which means it can't be a Perl subroutine).

    You can also use FFI.pm instead of Win32::API for accessing arbitrary subroutines from DLLs (or other types of shared libraries since FFI.pm is portable, very much unlike Win32::API). I'm not a big fan of the some aspects of the design of Win32::API anyway, though I suspect I'll find that FFI.pm and C::Dynalib (the other portable replacement for Win32::API that also existed before it) have their own things that annoy me once I use them enough.

            - tye (but my friends call me "Tye")
Re: Inspecting messages using Win32::API
by extremely (Priest) on Feb 16, 2001 at 11:22 UTC
    Hey, you may want to read up on how to post here. See Writeup Formatting Tips for example. You are working too hard at it if you start putting PRE tags around things. Just use the HTML P tag for paragraphs and stick CODE tags around your code. If you do that you'll find the fewer people ignore your post as poorly formatted.

    Oh yeah, and inside code tags all other html will display as raw text and your square brackets won't turn into links like when put your login in brackets here: mtaylor and here inside code tags [mtaylor] =) Best of all, the site is smart so single lines of code like in the last paragraph are displayed inline but blocks of code are shown as though they were in their own paragraph.

    Nice huh? Welcome to the site!

    --
    $you = new YOU;
    honk() if $you->love(perl)