Important Remarks on the Function Parameters of DLLs

Returning strings from the DLL to the application is always performed by returning a pointer to a memory area and, as a further parameter, an integer value for the length. The buffer size (in characters) must be passed so that buffer overflows are impossible. The string is always \0-terminated. If, for example, the buffer is too short, the returned string will be shortened and may result in incomplete return values. This is indicated by the API function's return value. LL_ERR_­BUFFER­TOO­SMALL will be returned in these cases.

The parameters are checked for correctness as far as possible. While developing a program it is therefore worth switching on the debug mode (see LlSetDebug()) and checking the return values. You can switch off the parameter check later using LL_OPTION_NOPARAMETERCHECK.

Please note that with Delphi the routines require "\0"-terminated strings just like the Windows API functions. It may be necessary to use the Pascal-string to C-string conversion routines.

With Visual Basic, it may in some cases be necessary to remove the '\0'-termination. Parameters are passed with ByVal. It is recommended that you initialize buffer/strings with…

Dim lpszBuffer As String * 255

to a specific size (here 255 bytes). This is also possible using…

lpszBuffer$ = space$(255)

but requires more time and memory. It is important to reserve the memory so that the DLL does not write in unused areas - an unhandled exception would be the result otherwise.

In addition, it must be noted that some functions cannot be supported with Visual Basic; these are, however, not normally required. You can find out which functions these are in the corresponding chapters. If a parameter value is NULL (C) or nil (Pascal), you should use "" (empty string) or 0 as value in Visual Basic, depending on the data type of the parameter. The OCX control does not need ANSIZ buffers, as it supports the native String data types.

Please note with C or C++ the C convention in source texts of having to enter, for example, the '\' in path entries twice: "c:\\temp.lbl" instead of "c:\temp.lbl".

Example:

INT    nSize = 16000;

LPWSTR pszBuffer = new TCHAR[nSize];

INT    nResult = <API>(hJob,...,pszBuffer,nSize);

 

if (nResult == LL_ERR_BUFFERTOOSMALL)

    {

    nSize = <API>(hJob,...,NULL,0);

 

    ASSERT(nSize > 0);

    delete[] pszBuffer;

    pszBuffer = new TCHAR[nSize];

    nResult = <API>(hJob,...,pszBuffer,nSize);

    }

 

...

 

delete[] pszBuffer;