在VB中调用 FindFirstFile 函数?
在VB中调用FindFirstFile 函数实现文件查找功能下面是VB中全部的代码
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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 '这么定义 在C中的定义char * cFileName[MAX_PATH]
cAlternateFileName As String '这么定义 在C中的定义char * cAlternateFileName[14]
'上面两句我不知道在VB中该如何定义
dwFileType As Long
dwCreatorType As Long
wFinderFlags As Integer
End Type
Private
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA"
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Sub Form_Load()
Dim lpFileName As String
lpFileName = String(256, Chr(0))
lpFileName = "c:\temp\32\p.exe"
Dim lpWin32FileData As WIN32_FIND_DATA
Dim re As Long
re = FindFirstFile(lpFileName, lpWin32FileData)
Text1.Text = re
End Sub
在c:\temp\32\中不放置p.exe的文件运行程序返回值为-1正常
我在c:\temp\32\中放值了一个叫p.exe的文件后,运行程序出现内存访问错误
(此时的调用函将会填充WIN32_FIND_DATA结构)
我想肯定就是WIN32_FIND_DATA中的cFileName和cAlternateFileName没有存贮空间的原因吧??
高手进来帮解答一下~