Perl for Win32 Module Extensions

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


Back to Perl5 Documentation Home

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. Due to some implementation issues that have yet to be resolved in Perl5 build 100 beta 1, writing extensions is still a little tricky. This document will be updated for the next build, which will have these issues addressed.

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 PerlAPI 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 MODIFICATIONSsection.
  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 1xx 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 perl100.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);
}



Back to Perl5 Documentation Home