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

I just installed Strawberry Perl 64 bit on a new laptop with an i3 as the processor. All is dandy except Win32::API cannot be compiled.

Although 32 bit applications run fine on such a computer (altough probably emulated), I can understand you cannot call 32 bit XS modules directly from within a 64 bit app...

But that also implies that the lower level Windows API functions (at least the 32 bit versions), are not available from within Perl.

Is there a workaround, like a "thunking layer", which was a solution back in the time when trying to run 16 bit applications on 32 bits Windows? (update: probably not)

Or is there a module like Win32::API but for 64 bits — and if so, how compatible is it, on the source level, for calling API functions? I can't seem to find anything... Is anything in the works?

update There was some discussion about starting up a porting project on the now defunct use.perl.org, in a post of almost 2 years ago. My, my, how time flies.

Replies are listed 'Best First'.
Re: Win32::API on 64 bits Windows Perl?
by BrowserUk (Patriarch) on Jan 14, 2011 at 11:57 UTC
    Is there a workaround, like a "thunking layer",

    No. You cannot call 32-bit dlls from 64-bit code.

    Or is there a module like Win32::API but for 64 bits

    Not that I've found, but there could be.

    The biggest problem is setting up the stack frames for the 64-bit calling convention without using a compiler.

    In many ways, the 64-bit calling convention is much simpler than the (various) 32-bit calling conventions. For a start, there is only one of them, and all parameter types are passed as 64-bit entities, mostly in registers.

    However, the removal of the _asm{} functionality from the 64-bit MSVC compiler means that you'd need a spot of MASM to facilitate the interfacing. Trouble is, the 64-bit MASM is extremely limited.

    It might actually be easier done with gcc with its built in assembler facilities, but that assembler is just weird.


    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.
Re: Win32::API on 64 bits Windows Perl?
by syphilis (Archbishop) on Jan 15, 2011 at 06:34 UTC
    There's some partial Win64 support in the github version:
    git clone git://github.com/cosimo/perl5-win32-api.git win32-api
    I actually have an API_test64.dll (different to the one on github) that allows t/API.t to pass its tests - but I think the partial support is for MS compilers only. Nothing there for x64 Strawberry Perl, afaik.

    Here's the best I can do with that github version:
    t/00_API.t .......... ok t/01_Struct.t ....... 1/7 # $^E= t/01_Struct.t ....... Dubious, test returned 5 (wstat 280, 0x500) Failed 2/7 subtests t/02_GetProcess.t ... 1/3 # $result=3980 # $$=3980 t/02_GetProcess.t ... ok t/03_undef.t ........ # Win32::API 0.60_64 t/03_undef.t ........ 1/3 # Import: The handle is invalid # PeekNamedPipe: The handle is invalid # Failed test '(RT \#39730) sample API (PeekNamedPipe) works with un +def values ' # at t/03_undef.t line 60. # Looks like you failed 1 test of 3. t/03_undef.t ........ Dubious, test returned 1 (wstat 256, 0x100) Failed 1/3 subtests t/04_rt_48006.t ..... 1/3 # Size is 296. Should be 296 t/04_rt_48006.t ..... ok t/05_more_struct.t .. ok
    It may be possible to do better with some simple hacking, but I don't pay much attention to Win32::API any more.
    Imo, if you want to access the Win64 API, best to do it with XS (or Inline::C) - and that goes for both ActivePerl and Strawberry Perl.

    Cheers,
    Rob

      The latest version from github supports also x64 Strawberry Perl - at least to the same extent as Active Perl.

      However:

      • Callbacks are not supported by neither Active|Strawberry Perl
      • AFAIK there are some minor issue with struct alignment on x64 (again on both Active|Strawberry Perl)

      --
      kmx