Use the following C code as an example of how to call a function that returns a variable length string. The code uses the var reportAlertInfo : PEReportAlertInfo) : boolean stdcall;, function which obtains the name of a field being used to sort the report and the direction of the sort. There are several other functions that return variable length strings, all of which are handled in a similar fashion.
Examine this code carefully and try to incorporate it into your own application without modifying the basic procedure. Only experienced programmers should try making changes to this technique since small mistakes here can cause major errors in your application. If you expect to use several REAPI functions that return variable length strings, you may want to set this code up in a separate function to avoid repetition and errors.
HANDLE nameHandle;
short nameLength;
short direction;
char *fieldName; PEGetNthSortField (printJob, sortFieldN,
&nameHandle, &nameLength,
&direction); /* allocate fieldName buffer */
fieldName = (char*)malloc(nameLength); PEGetHandleString ( nameHandle,
fieldName,
nameLength);
/*
** fieldName now contains name
** of field and nameHandle is no
** longer valid.
*/
Note: If you retrieve a string handle but do not retrieve the string itself (i.e., you do not use PEGetHandleString), you should free up the string memory by calling GlobalFree (nameHandle).
| Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |