3

ANSI文字列をFTP経由で新しいファイルに書き込む次のVisual Basic 6.0関数があります。ファイルを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
4

1 に答える 1

2

apiInternetWriteFile の宣言を確認する必要があります。おそらく、WinINet.dll の何かDeclareで、API 呼び出しに関係していると確信しています。私の推測では、次のことが必要です。

  • Declare を変更しByVal Longて、2 番目の引数にa が必要になるようにします。
  • 最初に BOM を取得するためにEDITContents = ChrW(&HFEFF&) & Contentsを試してください。またはFFEF、エンディアンがわからない可能性があります。
  • StrPtr(contents)第 2 引数に渡す
  • 第 3 引数に渡しLen(contents)*2ます (バイト単位の長さ)

これは、コンテンツ引数として Unicode UTF-16 文字列を渡します

于 2011-03-31T08:25:25.070 に答える