U2lwin32 UFL

This article was submitted .

This is a set of Custom User Functions (UFL) for Crystal Reports that allow access to some of the native Windows functionality.

Most of the functions deal with extracting information about Windows and its current setup. This includes getting information about the logged in user, language and other formatting settings. There's a number of functions to read and write from the System Registry, INI files and from basic text files.

The FileReadArray function is quite usefull to create reports that are translatable: Add the label translations in separate text files, then use the CurrentLanguage to load the appropriate text file. Finally create formula fields for each label to return the indexed text from the string array.
Use the FileAppendLine function to create a log file of who is watching your report. And use the SysColor to smoothly integrate the Crystal Report ActiveX viewer inside your application, so your report colors match the dialog/window of your app.
Note that the DateTimeToEpoch is replacable with the native Crystal function DateDiff("s", #1 Jan 1970#, Date1) which is slightly faster, but less readable. DateTimeToEpoch and its friends are highly needed if you store dates in your database as seconds since 1 Jan 1970 UTC or GMT.

The download contains an installation script for Crystal Reports 9. It can easily be adapted to later versions. It's a simple JavaScript file that copies the DLL file to the appropriate folder.
After installation, the new functions are available under the Additional Functions item in the Function Tree, in the module named Win32.


DateTimeToUtcAdjusts a local DateTime to UTC.
UtcToDateTimeAdjusts a DateTime value in UTC to local time.
DateTimeToEpochConverts a DateTime value to an Epoch date (known as "Unix time"; or the time_t structure). Expects local time and returns UTC number.
EpochToDateTimeConverts an Epoch date to a DateTime value. Returns a local time DateTime value.
TimezoneBiasReturns the current UTC timezone difference in minutes (daylight saving).
SysColorReturns a Windows System color. Use Windows native constants such as "COLOR_WINDOW" to specify what information to extract.
ReadIniValueReads a string from a Windows INI file.
WriteIniValueWrites a string to a Windows INI file.
ReadRegistryValueReads data from the registry. Both String and Integer values are read, but a string type is always returned.
WriteRegistryValueWrites a string to the registry.
WindowsDirReturns the path where Windows is installed.
SystemDirReturns the Windows System path.
AppDirReturns the path where the viewer is installed. When run from the Crystal Reports Designer this is the location of CR.EXE.
LoginNameReturns the login name of the current user.
ComputerNameReturns the Computer name.
RegisteredUserNameReturns the name of the registered user.
RegisteredCompanyReturns the company name of the registered user.
CurrentDirReturns the current directory.
CurrentLanguageReturns the current language identifier (abbreviated name of the language based on the ISO Standard 639).
CurrentCodePageReturns the active CodePage.
PrintDebugOutputSends a string to the Windows debug stream (Win32 OutputDebugString() function)
DriveSerialReturns the serial number of a disk drive/volume.
FileDeleteDeletes a file. Pass a complete filename to the function.
FileExistsReturns whether the file exists or not.
FileAppendLineAppends a line to a file. A newline character is automatically added.
FileReadArrayReads a file as an array of strings.
FormatArgsFormats a string with tokens, such as "Insert $1 here". Second argument is an array of strings which contains the replacement tokens.
LocaleInfoReturns Windows locale (country) information. Use Windows native constants such as "LOCALE_SCURRENCY" to specify what information to extract.
SystemMetricsReturns Windows System Metrics, such as screen size. Use Windows native constants such as "SM_CXFULLSCREEN" to specify what information to extract.
WindowsVersionReturns the Windows version as a decimal number (eg. 4.0 for Windows NT 4)
ShellExecuteLaunches an external application.
PlaySoundPlays a wave (.wav) file. Use an empty filename to stop playing.
SetClipboardTextAssigns text to the clipboard.
AnsiToOemConvert from ANSI charset to OEM.
OemToAnsiConvert from OEM charset to ANSI.
BORBinary OR.

Source Code Dependencies

Microsoft Visual C++ 6.0
Crystal Reports 9.0 (Dev.Ed)

Download Files  This software is free!

DownloadInstallation and sample (48 Kb)
Source Code (15 Kb)

To the top