askew
asked on
CRASH DUE TO ACCESS VIOLATION
Can anyone tell me why the following code crashes due to access violation. It crashes on the FindFirst instruction.
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
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 ' MAX_PATH
cAlternate As String ' 14
End Type
Private Sub Form_Load()
Dim X
Dim RS As WIN32_FIND_DATA
Dim db
db = "c:\TEMP\FILE2.PCA"
X = FindFirstFile(db, RS)
If X = -1 Then
MsgBox ("ERROR")
Else
MsgBox (RS.cFileName)
End If
End
End Sub
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
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 ' MAX_PATH
cAlternate As String ' 14
End Type
Private Sub Form_Load()
Dim X
Dim RS As WIN32_FIND_DATA
Dim db
db = "c:\TEMP\FILE2.PCA"
X = FindFirstFile(db, RS)
If X = -1 Then
MsgBox ("ERROR")
Else
MsgBox (RS.cFileName)
End If
End
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yep... Thanks for the points... but, why did you grade this with a "B"?
Cheers!
Cheers!
ASKER
sorry about the B, does that affect your rating?. I am trying to understand how api's work and an explanation of why I was wrong would have been helpful to me, though probably not to someone who just wanted to have code that worked. I will always grade as excellent in the future. Sorry again and thanks again.
It affects my score... Here is what an expert receives when a question is graded assuming that the question is posted for 100 points:
A= 400 quality points
B= 300 quality points
C= 200 quality points
D= dont even go there...
Cheers!
A= 400 quality points
B= 300 quality points
C= 200 quality points
D= dont even go there...
Cheers!
ASKER