Listing 1
Declaring the Win32 event log API functions function long RegisterEventSource( string pszServerName, string pszSourceName ) LIBRARY "ADVAPI32.DLL" alias for "RegisterEventSourceA"

function boolean ReportEvent( long hEventLog, integer wType, integer wCategory, long dwEventID, long pUserSID, integer wNumStrings, long dwDataSize, string pStringArray[], long pRawData ) LIBRARY "ADVAPI32.DLL" alias for "ReportEventA"

function boolean DeregisterEventSource( long hEventLog ) LIBRARY "ADVAPI32.DLL" alias for "DeregisterEventSource"

Listing 2
Example of writing to the event log
integer li_icon // The icon id (e.g. 1 = stop sign)
long ll_event_source_handle // The event log system's handle
string ls_message_array[] // The event log expects an array
string ls_server // The server whose log you want to write to
Boolean lb_result // Success or failure?

// Place "hello" into an array because the API
// call does not accept a simple string
ls_message_array[1] = "hello"

// Register the event source and get a handle
// to the WIN32 event logging system
SetNull(ls_server) // A null server means write locally
ll_event_source_handle = RegisterEventSource(ls_server, &
"NT Event Log Demo" )

// Log the message
lb_result = ReportEvent ( &
ll_event_source_handle, /* Handle for the event log */ &
li_icon, /* Icon type */ &
1, /* Category */ &
1, /* Event ID */ &
0, /* User ID */ &
1, /* Strings in the array */ &
0, /* Amount of raw data */ &
ls_message_array, /* Message array */ &
0 /* Raw data */ &
)
// Deregister the event source
DeregisterEventSource(ll_event_source_handle)

Listing 3
Declaring the Win32 file manipulation API functions function long FindFirstFile (ref string sPathName, ref s_file_data fd) LIBRARY "KERNEL32.DLL" alias for "FindFirstFileA"

function long FindNextFile (long lFileHandle, ref s_file_data fd) LIBRARY "KERNEL32.DLL" alias for "FindNextFileA"

function long MoveFile (String lpExistingFileName, String lpNewFileName) LIBRARY "KERNEL32.DLL" Alias for "MoveFileA"

Listing 4
Example of finding all files in a directory
s_file_data lstr_filedata // An array to hold file info
string ls_file_path // Path of the directory to process
string ls_file_name_this // Current file name
string ls_file_name_all // A list of all files
long ll_file_handle // Current file handle
long ll_more_files // Any more files?

// Find the first file in the temp directory
ls_file_path = "C:\TEMP\*.XML"
ll_file_handle = FindFirstFile (ls_file_path, lstr_filedata)

// Process any files in the temp directory
IF ll_file_handle = -1 THEN // -1 = no files found
MessageBox ("No files to process", &
"No XML files were found.", &
Exclamation!, &
OK!)
ELSE   DO
// Get the current file name from the
// structure and add it to the list
ls_file_name_this = lstr_filedata.ch_filename
ls_file_name_all = ls_file_name_all &
+ ls_file_name_this &
+ "~r~n"

// Get the next file
ll_more_files = FindNextFile (ll_file_handle, lstr_filedata)

LOOP WHILE ll_more_files = 1 // 0 = no more files

MessageBox ("XML Files", &
"These XML files were found.~r~n~r~n" &
+ ls_file_name_all, &
Information!, &
OK!)
END IF