Perl for Win32 Module Extensions

First read the PerlXS, PerlMod, and PerlGUTS man pages.


Win32 Extensions

ActiveWare


Introduction

The following document assumes the reader has a knowledge of writing module extensions for Perl, and is going to attempt to write one for Perl for Win32. Writing Win32 Perl extensions is still a little tricky. See the source for the Extensions for examples on how this is done.

Overview

Here is a quick overview of the steps used to write module extensions.

  1. An XS file is written. The format and conventions used in this file are described in the PerlXS man page.
  2. This XS file is 'compiled' with xsubpp. This creates a C++ file that can be compiled into a dll (renamed to .pll for dynamic libraries for Perl for Win32). There are some modifications that must be made to this file for this build, we are working to change this, these changes are described in the MODIFICATIONS section.
  3. A perl interface to the module is written (naming convention is to use the .pm suffix).

Modifications

In order to make extensions build with the current build of Perl for Win32, a few changes must be made to the C++ file generated by xsubpp. This is unfortunate, and will not be a permanent feature of Perl for Win32. Due to the way the perl300.dll was implemented, functions in the C++ file for the extensions that are not defined as XS(funcname) will cause compilation errors when they attempt to use any perl internal functions (eg: SvIV, etc). The way to fix this problem is to add 'CPerl* pPerl' as an argument to this function.

Eg:
// note the use of the pPerl here.

int constant(CPerl* pPerl, int arg)
{
    if(arg == 0)
    {
        printf("zero entered\n");
        return(0);
    }
    else
    {
        printf("a non-zero integer was entered\n");
        return(1);
    }
}

XS(MyPerlFunc)
{
    dXSARGS;
    int RETVAL;
    int arg;
    if(items < 1)
    {
        croak("usage: MyPerlFunc($value)\n");
    }
    arg = (int)SvIV(ST(0));
    // note pPerl is passed to subroutine here.
    RETVAL = constant(pPerl, arg);
    XSRETURN(RETVAL);
}



Win32 Extensions

ActiveWare