Please enable JavaScript to view this site.

ESL Documentation

Below is an example how to wrap an existing 'C' function so an ESL String variable can be passed safely to and from the function. The existing 'C' function (not included) converts a variable length input string to a fixed sized string. Even if the length of the input and output strings are the same, you must still use this technique to ensure the ESL String, which is part of the ESL Application memory, is not corrupted.

 

#include <windows.h>

#include "esllib.h"

 

LONG ESLSUBAPI Esl_LeftSet(PHSTRING EslString, PLONG EslLength)

{

    LONG    RetCode=0;

    PCHAR   InputString;

    PCHAR   OutputString;

    USHORT  FieldLen;

    size_t  size;

 

/* Uncomment the function below if you need to debug this routine */

//        DebugBreak();

 

  FieldLen = (USHORT) *EslLength;

 

/* The pointer returned by the ESL function must not be passed to user        */

/* written functions as they may accidentally alter the content of the string.*/  

  InputString = EslQueryStringAddr(*EslString);

 

/* It is safe to use a standard C function to obtain the string length. */

 size = strlen(InputString);

 

/* Add a byte to allow for the NULL terminator */

 size++;

 if (InputString = malloc(size))

 {

        /* If the memory allocation is OK copy the characters to the buffer. *

         EslQueryStringChars(*EslString, InputString, (LONG)size);

 

        /* Allocated pre-NULL'ed buffer for the Output String */

         if (OutputString  = calloc( (FieldLen+1),  sizeof( char )))

       {

              /* If allocation OK call the existing C function */

                 LeftSet(InputString, OutputString, FieldLen);

 

              /* Convert the output back to an ESL String */

                 EslSetStringValue(EslString, OutputString, (LONG)strlen(PString));

 

              /* de-allocate the Output buffer */

                 free(OutputString);

         }

         else

                 RetCode = -1;

 

        /* de-allocate the Input buffer */

         free(InputString);

 }

 else

         RetCode = -2;

 

 

    return RetCode;

}

 

Note. The return code is used to indicate to the ESL application whether the routine was successful or which memory allocation had failed. The return code is accessible via the "errorlevel" pseudo variable.