Consultor Eletrônico



Kbase P8011: How to use DLLFUNC function in Report Builder
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/27/2009
Status: Verified

GOAL:

How to use DLLFUNC function in Report Builder

GOAL:

Sample Code - DLLFUNC in Report Builder

FACT(s) (Environment):

Progress 8.x
Progress 9.x
Windows

FIX:

If you need to use DLLFUNC() in Report Builder to do complex calculations that Report Builder does not support, the following example will show you how to use DLLFUNC() to access an external DLL containing C code.

DLLFUNC expects a Boolean return value from the called DLL function.

TRUE to indicate the function executed successfully.
FALSE to indicate an error.

If the DLL function executes successfully, it should overwrite its input string with the output string to be returned by the Report Builder DLLFUNC.

The function in the DLL must take a character string as an argument and return a boolean value. The DLL in the example contains one function, TestDllFunc. If you pass "dog" to this function, it changes it to "poodle" and returns TRUE. If you pass anything else, it returns FALSE, which causes Report Builder to display "????????".

Here is the sample C code, how to declare the function so that RB can call it.

#include "windows.h"

BOOL _declspec(dllexport) WINAPI TestDllFunc(LPSTR lpString)
{
if (!lstrcmp(lpString, "dog"))
{
strcpy(lpString, "poodle");
return TRUE;
}
else
return FALSE;
}

#end of code sample

In the Report you insert a calculated field.
In the expression you call the DLL using function DLLFUNC(dll-name, function-name, string). If you create a Report using Sports database, insert cust-num field and the following example in an expression of a calculated field next to cust-num, it shows the word "poodle" for the customers with even cust-num. It display "????????" for customers with odd cust-num.

If you compiled the previous code in c:\work\rbdlltest.dll, use following expression.

dllfunc("c:\work\rbdlltest.dll", "TestDllFunc", iif(((cust-num - integer(cust-num / 2) * 2) = 0), "dog", "cat"))

FIX:

References to Written Documentation

Report Builder User's Guide - Report Builder Functions