I have the following Visual Basic 6.0 function which writes an ANSI string to a new file over FTP. I would like it to write the file as UTF-16LE. Is there any good way to do that within this following method?
Public Sub writeToFile(ByVal FTPServer As String _
, ByVal userName As String _
, ByVal password As String _
, ByVal contents As String _
, ByVal destinationFile As String)
Dim hFile As Long
Dim lCount As Long
inetOpen
inetConnect FTPServer, userName, password
hFile = apiFtpOpenFile(m_hFTP, destinationFile, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0&)
If hFile = 0 Then
Err.Raise EWMFTPErrorCodes.wmFTPSendError, , internetError
End If
If apiInternetWriteFile(hFile, contents, Len(contents), lCount) = 0 Then
Err.Raise EWMFTPErrorCodes.wmFTPSendError, , internetError
End If
apiInternetCloseHandle hFile
End Sub
I haven't done Visual Basic 6.0 in about 10 years, so I'm shaky at best. Any input would be greatly appreciated.
Here is the apiInternetWriteFile declaration;
Private Declare Function apiInternetWriteFile Lib "wininet.dll" Alias "InternetWriteFile" ( _
ByVal hFile As Long _
, ByVal lpBuffer As String _
, ByVal dwNumberOfBytesToWrite As Long _
, ByRef lpdwNumberOfBytesWritten As Long) As Long
We need to see the declaration for apiInternetWriteFile. I'm pretty sure it's a Declare
into an API call, maybe something in WinINet.dll. My guess is that you need to:
ByVal Long
for the 2nd argument Contents = ChrW(&HFEFF&) & Contents
. Or possibly FFEF
, not sure of the endianness.StrPtr(contents)
for the 2nd argumentLen(contents)*2
for the 3rd argument (length in bytes)That will pass a Unicode UTF-16 string as the contents argument