Solved

CRASH DUE TO ACCESS VIOLATION

Posted on 2000-03-02
5
328 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:askew
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2577220
Try this, it works on my system:

Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Const MAX_PATH = 260
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 As Long
Dim RS As WIN32_FIND_DATA
Dim db As String

db = "c:\TEMP\FILE2.PCA"
X = FindFirstFile(db, RS)
If X = -1 Then
    MsgBox ("ERROR")
Else
    MsgBox (RS.cFileName)
End If
End Sub


Cheers!
0
 

Author Comment

by:askew
ID: 2578124
Thanks a lot. Guess I really needed to define those string lengths in WIN32_FIND_DATA
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2578814
Yep... Thanks for the points... but, why did you grade this with a "B"?


Cheers!
0
 

Author Comment

by:askew
ID: 2580204
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.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2580400
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!
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Restricting text box entry from \/:?<>"| 9 88
Validating VB6 Function 19 61
Paint/Redraw window while dragging 16 78
MS Date Picker 64 bit 32 bit issue 12 55
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question