Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Using GetWindowThreadProcessId(). Want to move to AS 5.16 64bit Perl, but Win32::GUI doesn't build. Now what?

by KalTorak (Initiate)
on May 28, 2013 at 18:49 UTC ( #1035681=perlquestion: print w/ replies, xml ) Need Help??
KalTorak has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to finally migrate all my distributed pool to ActiveState's 5.16 64bit Perl. Problem is, the PPMs all seem to report that Win32::GUI doesn't build for 64-bit Perl. (Of course, it also says Win32::GUI doesn't build for 5.8 32-bit Perl, and I've GOT one, so not sure what that means.)

Anyway - can I work around this?

The only function in Win32::GUI I'm using is Win32::GUI::GetWindowThreadProcessId.

I'm creating a Win32::OLE object (from which I can directly obtain an Hwnd), and using that Hwnd to get a PID, with which I can shoot it down later if it misbehaves.

  • Can I obtain a PID for my OLE object without using any functions in Win32::GUI?
  • Is there another surefire way to shoot down a misbehaving OLE object?
  • Comment on Using GetWindowThreadProcessId(). Want to move to AS 5.16 64bit Perl, but Win32::GUI doesn't build. Now what?
    Re: Using GetWindowThreadProcessId(). Want to move to AS 5.16 64bit Perl, but Win32::GUI doesn't build. Now what?
    by Anonymous Monk on May 28, 2013 at 19:18 UTC
    Re: Using GetWindowThreadProcessId(). Want to move to AS 5.16 64bit Perl, but Win32::GUI doesn't build. Now what?
    by Anonymous Monk on May 28, 2013 at 19:21 UTC
    Re: Using GetWindowThreadProcessId(). Want to move to AS 5.16 64bit Perl, but Win32::GUI doesn't build. Now what?
    by BrowserUk (Pope) on May 28, 2013 at 19:42 UTC

      If all you need is that one function, you can easily get at it with Inline::C:

      #! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'GWTPI', CLEAN_AFTER_BUILD =>0; #include <windows.h> #define IS_VARS Inline_Stack_Vars #define IS_RESET Inline_Stack_Reset #define IS_PUSHIV( iv ) Inline_Stack_Push( sv_2mortal( newSViv( iv ) ) + ) #define IS_PUSHUV( uv ) Inline_Stack_Push( sv_2mortal( newSVuv( uv ) ) + ) #define IS_DONE Inline_Stack_Done void getWindowThreadProcessId( SV* hwnd ) { IS_VARS; DWORD pid; DWORD tid = GetWindowThreadProcessId( (HWND)SvUV(hwnd), &pid ); IS_RESET; IS_PUSHUV( tid ); IS_PUSHUV( pid ); IS_DONE; return; } END_C my( $tid, $pid ) = getWindowThreadProcessId( 0 ); print "$tid $pid";

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Since the OP is wanting to distribute the code, it becomes necessary to ensure that Inline::C is installed on the target machines (or other appropriate action taken).

        <PLUG>
        I would therefore probably take the code that BrowserUk provided and turn it into a standalone module - which could be distributed in either source or pre-built (binary) form.
        First, create a directory ./Win32-ThreadID-0.01 and a file ./ThreadID.c; where ThreadID.c contains the following section of BrowserUk's code:
        #include <windows.h> #define IS_VARS Inline_Stack_Vars #define IS_RESET Inline_Stack_Reset #define IS_PUSHIV( iv ) Inline_Stack_Push( sv_2mortal( newSViv( iv ) ) + ) #define IS_PUSHUV( uv ) Inline_Stack_Push( sv_2mortal( newSVuv( uv ) ) + ) #define IS_DONE Inline_Stack_Done void getWindowThreadProcessId( SV* hwnd ) { IS_VARS; DWORD pid; DWORD tid = GetWindowThreadProcessId( (HWND)SvUV(hwnd), &pid ); IS_RESET; IS_PUSHUV( tid ); IS_PUSHUV( pid ); IS_DONE; return; }
        Then run this script:
        use warnings; use strict; use InlineX::C2XS qw(c2xs); my $mod = 'Win32::ThreadID'; my $pkg = $mod; my $build_dir = './Win32-ThreadID-0.01'; c2xs($mod, $pkg, $build_dir, {WRITE_PM => 1, WRITE_MAKEFILE_PL => 1, VERSION => '0.01', MANIF => 1, SRC_LOCATION => './ThreadID.c', EXPORT_OK_ALL => 1, });
        That will create a Win32-ThreadID-0.01 source distro in the Win32-ThreadID-0.01 directory - complete with ThreadID.pm, ThreadID.xs, Makefile.PL, INLINE.h and MANIFEST, where ThreadID.pm exports (upon request) the getWindowThreadProcessId function. That distro as it then stands is already buildable and installable - though there's yet no test script (which would have to be added by hand, if desired).
        </PLUG>

        Hmmm .... come to think of it, an option to generate a test script (that simply tests the loadability of the module) might be a useful addition to InlineX::C2XS ...

        Cheers,
        Rob

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlquestion [id://1035681]
    Approved by Corion
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (12)
    As of 2014-10-02 13:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (59 votes), past polls