How to use Windows API functions in Visual Report Writer
by
, 19-Jul-2013 at 04:37 PM (106678 Views)
In this blog I’ll show you how to use Windows API functions in Visual Report Writer.
We are using the function PathFileExists exposed by the library ‘Shlwapi.dll ‘
Visual Report Writer uses the VARIANT type to communicate with the External Library Functions (ELF). Because of this Windows API’s can’t be called directly, doing so will stop the rendering of the reports as Visual Report Writer expects a variant type to return and direct calling might even crash the Visual Report Writer.
To call windows API functions we have to use wrapper functions that converts the variant type of Visual Report Writer to the types that the API call wants.
Please read the blog http://support.dataaccess.com/Forums...e-your-own-ELF for an explanation on how to create a ELF dll. The DLL created by that blog will be used here.
The variants uses Unicode to format the strings, thus we are using the Unicode variant of PathFileExists called PathFileExistsW. Include the header file of Shlwapi at the top of ExternalLibraryFunctions.cpp file to access the function.
Add the next code to the end of ExternalLibraryFunctions.cpp to convert the call made by Visual Report Writer to the API function.Code:#include "Shlwapi.h"
To expose the function we add in ExternalLibraryFunctions.def the next line of code at the end of the EXPORTS sectionCode:VARIANT __declspec(dllexport) FileExists(VARIANT PathFile) {char *pszPath; int retval; CComVariant vRes; USES_CONVERSION; // Check argument type if (PathFile.vt != VT_BSTR) {vRes.vt = VT_ERROR; vRes.scode = MAKE_HRESULT(1,FACILITY_ITF,1); return vRes;} retval = PathFileExistsW(PathFile.bstrVal); // return a boolean instead of a integer variable vRes = (retval==1); return vRes;}
Now the export section looks like :Code:FileExists
We can build the library and copy the resulted dll file to the folder where Visual Report Writer resides. Add the ELF to Visual Report Writer and use it like :Code:EXPORTSnumber2words FileExists
Happy codingCode://check if there is a logo of the customer if (FileExists("C:\logos\" + {Customer.Name} + ".jpg")) thenreturn "C:\logos\" + {Customer.Name} + ".jpg"elsereturn ""end
Bénar Bloemendal