我有以下Visual Basic 6.0函数,它通过FTP将ANSI字符串写入新文件。我希望它将文件写为UTF-16LE。在以下方法中有没有什么好办法呢?
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
我在大约10年内没有完成Visual Basic 6.0,所以我充其量只是摇摇欲坠。任何意见都将不胜感激。
这是apiInternetWriteFile声明;
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
答案 0 :(得分:2)
我们需要查看apiInternetWriteFile的声明。我很确定它是API调用的Declare
,可能是WinINet.dll中的something。我的猜测是你需要:
ByVal Long
Contents = ChrW(&HFEFF&) & Contents
。或者可能FFEF
,不确定字节顺序。StrPtr(contents)
作为第二个参数Len(contents)*2
作为第三个参数(长度,以字节为单位)这将传递Unicode UTF-16字符串作为内容参数