Calling DLL Functions on the Application Server

To support processes running on an application server, you can declare and call functions compiled in Microsoft Windows DLLs and in UNIX shared libraries (or shared objects, depending on the specific UNIX platform). You can do this either with a special PeopleCode declaration, or using the business interlink framework.

When you call out to a DLL using PeopleCode, on Microsoft Windows NT application servers, the DLL file has to be on the path. On UNIX application servers, the shared library file must be on the library path (as defined for the specific UNIX platform).

The PeopleCode declaration and function call syntax remains unchanged. For example, the following PeopleCode could be used to declare and call a function LogMsg in an external library Testdll.dll on a Microsoft Windows client or a Windows application server, or a libtestdll.so on an UNIX application server. The UNIX shared library’s extension varies by the specific UNIX platform.

Declare Function LogMsg Library "testdll" (string, string)
       Returns integer;

&res = LogMsg("\temp\test.log", "This is a test");

The following section describes and includes the C source code for a sample cross-platform test fucntion: LogMsg. It is a basic function that opens a log file and appends a line to it. If you compile the code using a C++ compiler, the functions must be declared using external C to ensure C-language linkage.

The sample program also contains an interface function (LogMsg_intf). Prior to PeopleTools 8.52, this interface function was required for all non-Microsoft Windows environments. The interface function references a provided header file, pcmext.h. The interface function is passed type codes that can be optionally used for parameter checking.

Starting with PeopleTools 8.52, the interface function is required for the following environments only:

  • HP-UX Itanium

  • Solaris x86_64

  • z/Linux

For all the other PeopleTools-supported UNIX platforms, the functions from the UNIX shared libraries can be used directly. To maintain backward compatibility, the interface functions are also supported on these UNIX platforms.

In the following sample test program, the interface function is compiled only when compiling for the specified non-Windows environments.

/*
 * Simple test function for calling from PeopleCode.
 * This is passed two strings, a file name and a message.
 * It creates the specified file and writes the message 
 * to it.
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _WINDOWS
#define DLLEXPORT __declspec(dllexport)
#define LINKAGE __stdcall
#else
#define DLLEXPORT
#define LINKAGE
#endif

DLLEXPORT int LINKAGE LogMsg(char * fname, char * msg);

/********************************************************
*  PeopleCode External call test function.              *
*                                                       *
*  Parameters are two strings (filename and message)    *
*  Result is 0 if error, 1 if OK                        *
*                                                       *
*                                                       *
*  To call this function, the following PeopleCode is   *
*  used                                                 *
*                                                       *
*  Declare Function LogMsg Library "testdll"            *
*  (string, string)                                     *
*       Returns integer;                                *
*                                                       *
*  &res = LogMsg("\temp\test.log", "This is a test");   *
*                                                       *
********************************************************/

DLLEXPORT int LINKAGE LogMsg(char * fname, char * msg)
{
    FILE *fp;

    fp = fopen(fname, "a");         /* append */
    if (fp == NULL) return 0;

    fprintf(fp, "%s\n", msg);
    fclose(fp);
    return 1;
}


#ifndef _WINDOWS

/********************************************************
*  Interface function.                                  *
*                                                       *
*  This is not needed for Windows....                   * 
*                                                       *
********************************************************/

#include  "pcmext.h"
#include  "assert.h"

/* This interface function is required only for the following platforms:
   - HP-UX Itanium 
   - Solaris x86_64 
   - z/Linux
*/

void LogMsg_intf(int nParam, void ** ppParams, EXTPARAMDESC * pDesc)
{
    int    rc;

    /* Some error checking */
    assert(nParam == 2);
    assert(pDesc[0].eExtType == EXTTYPE_STRING
       && pDesc[1].eExtType == EXTTYPE_STRING
       && pDesc[2].eExtType == EXTTYPE_INT);

    rc = LogMsg((char *)ppParams[0], 
         (char *)ppParams[1]);
    *(int *)ppParams[2] = rc;

}

#endif