Release 10.1A: OpenEdge Development:
Programming 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, Progress Software recommends that you pass the Progress character string in a `MEMPTR` memory region as a null-terminated string. This is required if it is an `OUTPUT` parameter. Otherwise, the shared library routine might inappropriately modify Progress memory outside the bounds of the `CHARACTER` value with unpredictable results. Assuming Progress has allocated the memory for the string (using `SET-SIZE`), you then use the `GET-STRING` function to extract the `CHARACTER` value.

> If the DLL alllocates the memory as either a `RETURN` value or an `OUTPUT` parameter, you must use an `OUTPUT` `MEMPTR`. For a `RETURN` parameter, you can use `GET-STRING` (or another access function) directly on the `MEMPTR` on return. However, for an `OUTPUT` parameter, you must use the `GET-POINTER-VALUE` and `SET-POINTER-VALUE` functions to access the data on return. (For more information on the `GET-` and `SET-POINTER-VALUE` functions, see OpenEdge Development: Progress 4GL Reference .)

> The following code fragment shows how to pass an `INPUT-OUTPUT` string value as a `MEMPTR` parameter in the case where Progress allocates the memory:

>     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.
>                         .
>                         .
>                         .
>     /* The longest string the DLL returns is 256 characters */
>     len = LENGTH(CharString).
>     siz= (IF len >256 THEN
>                     len ELSE 256)
>     SET-SIZE(MemptrVar) = siz.
>     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 both the input and output CharString values. The `PUT-STRING` statement stores the CharString value in MemptrVar. After passing MemptrVar to the DLL routine, the `GET-STRING` statement returns the (new) value to CharString.

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