The Problem with Win32

Sébastien Aperghis-Tramoni,

The problem

  • Windows sucks

  • </troll> ;-)

The real problem

  • Windows is hard (baroque API, irregular documentation)

    • MSDN contains many interesting information, but its search engine and translator are very good to hide all they can from you

  • Windows is not freely available

    • Which will come first: a usable ReactOS or a free Win32?

The real problem

  • Windows compilers and tools were not freely available for a long time

    • Microsoft now gives you Visual C++ for free, but of course won't tell anyone about this except on a hidden page. Also available, Borland BCC and Watcom compilers.

  • Windows is x86 only

    • Older sysadmins may remember the times when NT4 was available on PowerPC, MIPS, Alpha and HP-PA.


  • Realise that we don't care of all this

  • Windows API provided in Perl by the Win32, Win32::* and Win32API::* modules

  • Therefore we just need to mock these modules


  • Pure-Perl reimplementation of Win32 functions and modules

  • Allows for instrumentation (very useful for tests)

  • Does not interfere with real Win32 modules


  •     use Win32::Mock;
        # @INC has now been modified to un-hide the mocked Win32 modules
  •     use Win32;  # now always works
  •     printf "This is Perl $] (build %s) on %s, running on host %s\n", 
            Win32::BuildNumber(), ~~Win32::GetOSName(), Win32::NodeName();

Source code

  • The full source code of Win32::Mock

  •     package Win32::Mock;
        $VERSION = '0.01';
        use strict;
        use File::Basename;
        use File::Spec::Functions;
        use Devel::FakeOSName "Win32/\u$^O";
        use lib catdir(dirname($INC{"Win32/"}), "Mock");