unicode - 通过 FTP 将 ANSI 字符串写入 Unicode 文件

标签 unicode vb6 ansi unicode-string

我有以下 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

最佳答案

我们需要查看 apiInternetWriteFile 的声明。我很确定这是 API 调用中的Declare,也许 something在 WinINet.dll 中。我的猜测是你需要:

  • 更改 Declare,以便第二个参数需要 ByVal Long
  • 编辑要在开始时获取 BOM,请尝试 Contents = ChrW(&HFEFF&) & Contents。或者可能是 FFEF,不确定字节序。
  • 传递 StrPtr(contents) 作为第二个参数
  • 传递 Len(contents)*2 作为第三个参数(长度以字节为单位)

这将传递一个 Unicode UTF-16 字符串作为内容参数

关于unicode - 通过 FTP 将 ANSI 字符串写入 Unicode 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5496110/

相关文章:

c# - C++ 库适用于 vb6 但不适用于 c#

terminal - 转义码 VT102 和 ANSI

c - 将 sprintf 与 char * 一起使用

c - 取消初始化整数指针的赋值

PHP:如何创建 unicode 文件名

ios - 使用 unicode 字符时 NSString 中的通用字符名称错误,<

python - 阿拉伯语 - Python 2.7 中的 UnicodeDecodeError

python - 如何替换 r'\xb 0' with r'\260'

string - 子串的VB6索引

memory - 在 VB6 应用程序中识别内存占用的工具