【问题标题】:data type mismatch in FtpFindFirstFileFtpFindFirstFile 中的数据类型不匹配
【发布时间】:2013-04-05 20:46:08
【问题描述】:

我正在使用以下函数枚举一个 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

知道为什么我会收到这个错误吗?

【问题讨论】:

  • 请编辑您的问题以在该模块中显示WIN32_FIND_DATAType 声明,以及完整的Declare Function FtpFindFirstFile 行。
  • @GordThompson 我添加了请求的代码。谢谢

标签: ms-access vba ms-access-2007 wininet


【解决方案1】:

我有一个工作示例,我找到了here,我的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

【讨论】:

  • 谢谢!我会尝试并回帖!
猜你喜欢
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
相关资源
最近更新 更多