Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : Shared Library and DLL Support : Passing parameters to a shared library routine : Passing arrays as parameters : CHARACTER and LONGCHAR arrays
 
CHARACTER and LONGCHAR arrays
If the DLL requires an array of strings as INPUT which is represented by an array of pointers to strings, you can pass an ABL CHARACTER or LONGCHAR array. You can do the same if it is an INPUT-OUTPUT parameter, however, this is not recommended. If the DLL updates the data such that the output string is longer than the input string, this can result in a memory exception or other unpredictable behavior. Therefore, for INPUT-OUTPUT parameters you should use a MEMPTR array, described in MEMPTR arrays.
Also, just as you cannot pass CHARACTER or LONGCHAR OUTPUT parameters to a DLL, you also cannot pass a CHARACTER or LONGCHAR array as an OUTPUT parameter. If the DLL requires an array of character buffers that it will modify or if the DLL allocates memory for a set of strings and returns them as an array of pointers, you should use a MEMPTR parameter.
As with the INTEGER and DECIMAL types of arrays, the data type in the prototype can be either just the type (for example, CHARACTER) or you can specify it with the HANDLE TO option.
Here is an example C Code Prototype for a function called nameLookup:
nameLookup(char **ppStrArray, char *pfindName);
This example is the equivalent ABL for the nameLookup procedure when accessing the function statically:
DEFINE VARIABLE cFindName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNames    AS CHARACTER NO-UNDO EXTENT 50.

RUN nameLookup (cNames, cFindName).

PROCEDURE nameLookup EXTERNAL "myApp.dll" PERSISTENT:
  DEFINE INPUT PARAMETER ppStrArray AS HANDLE TO CHARACTER.
  DEFINE INPUT PARAMETER pfindName AS CHARACTER.
END.
This example is the equivalent ABL for the nameLookup procedure when accessing the function dynamically:
DEFINE VARIABLE cFindName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNames    AS CHARACTER NO-UNDO EXTENT 50.
DEFINE VARIABLE hCall     AS HANDLE    NO-UNDO.

CREATE CALL hCall.
ASSIGN
  hCall:CALL-NAME             = "nameLookup"
  hCall:LIBRARY               = "myApp.dll"
  hCall:CALL-TYPE             = DLL-CALL-TYPE
  hCall:RETURN-VALUE-DLL-TYPE = "CHARACTER"
  hCall:PERSISTENT            = TRUE
  hCall:NUM-PARAMETERS        = 2.

hCall:SET-PARAMETER(1, "CHARACTER", "INPUT", cNames).
hCall:SET-PARAMETER(2, "CHARACTER", "INPUT", cFindName).
hCall:INVOKE( ).