(c) 2002 Visual Studio Magazine
Fawcette Technical Publications

January 2002 issue
"Add File Replication to Your App" 
by Monte Hansen


VB5, VB6	Access a File System Using Globalization
Listing 1	Use globalization techniques to access a file system from across the globe. This function wrapper adds dynamic support for ANSI and Unicode, depending on the operating system where the file system runs. 

Declare Function DeleteFileA Lib "kernel32" _
	(ByVal lpFilename As String) As Long
Declare Function DeleteFileW Lib "kernel32" _
	(ByVal lpFilename As Long) As Long 

Public Function DeleteFile(ByVal lpFilename As _
	String) As Long
	If IsWinNt() Then  
		' running on NT+; use WIDE function
		DeleteFile = DeleteFileW( _
			StrPtr(lpFilename))
	Else
		' running on Win9X; use ANSI function
		DeleteFile = DeleteFileA(lpFilename)
	End If
End Function

VB5, VB6	Support Both ANSI and Unicode
Listing 2	This globalization technique allows the calling application to use the same structure for ANSI and Unicode versions of the FindFirstFile function. This custom version of the WIN32_FIND_DATA structure uses a byte array for the last parameter, which is large enough to support both ANSI and Unicode.

Private Type WIN32_FIND_DATA_X
	' WIN32_FIND_DATA for use with
	' WIDE & ANSI function calls
	dwFileAttributes	As Long
	ftCreationTime	As FILETIME
	ftLastAccessTime	As FILETIME
	ftLastWriteTime	As FILETIME
	nFileSizeHigh	As Long
	nFileSizeLow	As Long
	dwReserved0	As Long
	dwReserved1	As Long
	' This buffer holds cFileName 
	' and cAltFileName. It's sized for 
	' the wide call but can also be 
	' used for the ANSI call as well:
	Buffer(1 To (260 + 16) * 2) As Byte
End Type

' fixed part of WIN32_FIND_DATA structure
Const m_Win32Fixed As Long = 44 

Private m_FindData As WIN32_FIND_DATA_X

VB5, VB6	Route the Call to the Correct Class
Listing 3	The WinInet callback function supplies a pointer to any class that implements the IInternetStatus interface. The FtpConnection and FtpFileStream classes use this interface to receive callbacks from the WinInet library.

Public Sub INTERNET_STATUS_CALLBACK ( _
	ByVal hInternet As Long, _
	ByVal dwContext As Long, _
	ByVal dwInternetStatus As Long, _
	ByVal lpvStatusInformation As Long, _
	ByVal dwStatusInformationLength As Long)

	Dim InternetObj As IInternetStatus

	On Error GoTo ExitLabel

	' Get owner of this status InternetObj.
	' It can be any class that Implements
	' the IInternetStatus interface.
	Set InternetObj = PtrToObj(dwContext)

	Call InternetObj.Callback(dwInternetStatus, _
		lpvStatusInformation, _
		dwStatusInformationLength)

ExitLabel:
	Debug.Assert (Err.Number = 0)
End Sub
