1

次の関数を使用して ftp ディレクトリを列挙しています。

Public Sub EnumFiles(hConnect As Long)
Const cstrProcedure = "EnumFiles"
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
Dim strSubCode As String
Dim sql As String
On Error GoTo HandleError

sql = "INSERT INTO tblIncomingFiles (AvailableFile) Values ('" & pData.cFileName & "')"
'get sub code to search with
strSubCode = GetSubscriberCode
'create a buffer
pData.cFileName = String(MAX_PATH, 0)
'find the first file
hFind = FtpFindFirstFile(hConnect, "*" & strSubCode & "*", pData, 0, 0)
'if there's no file, then exit sub
If hFind = 0 Then Exit Sub
'show the filename
Debug.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
CurrentDb.Execute sql
Do
    'create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    'find the next file
    'lRet = FtpFindNextFile(hFind, pData.cFileName)
    'if there's no next file, exit do
    If lRet = 0 Then Exit Do
    'show the filename
    'Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    CurrentDb.Execute sql
Loop
'close the search handle


HandleExit:

    Exit Sub

HandleError:
    ErrorHandle Err, Erl(), cstrModule & "." & cstrProcedure
    Resume HandleExit
End Sub

次の行にデータ型の不一致 (エラー 13) が表示され続けます。

hFind = FtpFindFirstFile(hConnect, "*" & strSubCode & "*", pData, 0, 0)

pData が強調表示されます。関数の先頭で pData を WIN32_FIND_DATA として宣言しており、このモジュールでは WIN32_FIND_DATA が型として宣言されています。

Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal sSearchFile As String, ByVal lpFindFileData As Long,   _
ByVal lFlags As Long, ByVal dwContext As Long) As Long

Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

なぜそのエラーが発生するのか考えていますか?

4

1 に答える 1

1

ここで見つけた実際の例があり、私のFtpFindFirstFile宣言はあなたのものとは少し異なります。私のは

Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, _
ByVal dwFlags As Long, ByVal dwContent As Long) As Long
于 2013-04-08T19:18:03.293 に答える