Progress
External Program
Interfaces


Passing CHARACTER Values To Shared Library Routines

If you are passing a Progress character string to a shared library routine, you can pass it as a CHARACTER variable or expression. However, if you expect the shared library routine to modify the value, you must set up and pass the Progress character string in a MEMPTR memory region as a null-terminated string. Otherwise, the shared library routine might inappropriately modify Progress memory outside the bounds of the CHARACTER value with unpredictable results. To return a character string from a shared library routine, the OUTPUT parameter must be a MEMPTR. You then use the GET-STRING function to extract the CHARACTER value.

The following code fragment shows how to repackage a CHARACTER value in a MEMPTR memory region, and return the new value from a DLL routine:

DEFINE VARIABLE MemptrVar AS MEMPTR.
DEFINE VARIABLE CharString AS CHARACTER.

PROCEDURE DLLfunction EXTERNAL anysystem.dll ORDINAL 10:
  DEFINE INPUT-OUTPUT PARAMETER StringParm AS MEMPTR.
END PROCEDURE.
                    .
                    .
                    .
SET-SIZE(MemptrVar) = LENGTH(CharString) + 1.
PUT-STRING(MemptrVar,1) = CharString.

RUN DLLfunction (INPUT-OUTPUT MemptrVar).

CharString = GET-STRING(MemptrVar).
                    .
                    .
                    . 

The DLL routine is the tenth function in the anysystem.dll file. The SET-SIZE statement allocates to MemptrVar a memory region large enough to hold the CharString value plus a null terminator. The PUT-STRING statement builds a structure with one location containing the null-terminated value of CharString. After passing MemptrVar to the DLL routine, the GET-STRING statement returns the (new) value to CharString.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095