[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SearchTreeForFile crashing VB6, using Windows XP Pro

Posted on 2005-04-08
16
Medium Priority
?
666 Views
Last Modified: 2012-05-05
Hello,

I have been using SearchTreeForFile API for quite some time in a VB6 program, but all of a sudden, the SearchTreeForFile API is making VB6 crash.  I thought it may be related to the imagehlp.dll file being corrupt, so I swapped it with a new one, and I am still getting the same results.  I then had some older versions of the dll file, and had SearchTreeForFile referenced to it, and VB6 will not crash, but it will not search an entire drive, it will only find the file if I point to the exact directory in which it is located.

Has anyone experienced this phenomena before?  I'm open to any kind of suggestions, because I'm feeling a little dead in the water at this moment.

Thank You,
Drumsticks
0
Comment
Question by:Drumsticks
  • 11
  • 4
16 Comments
 
LVL 8

Expert Comment

by:anthonywjones66
ID: 13738578
How do you know it is SearchTreeFOrFile that is causing this?
What exactly is the exception in the crash?
Can you show a little code leading up to the Call to this API?

Anthony.
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13738671
Hello anthony,

Thank you for the quick response!

The only reason why I know it has something to do with SearchTreeForFile is because I stripped an example of only the SearchTreeForFile API and made an exclusive VB project.  The example crashes VB6 as well.

Here is the example:

******PLACE THIS CODE IN A MODULE******
Option Explicit

Declare Function SearchTreeForFile Lib "IMAGEHLP.DLL" _
    (ByVal lpRootPath As String, _
    ByVal lpInputName As String, _
    ByVal lpOutputName As String) As Long
Public Const MAX_PATH = 260

Public Function FindFile(RootPath As String, FileName As String) As String
Dim lNullPos As Long
Dim lResult As Long
Dim sBuffer As String
     
On Error GoTo FileFind_Error
    sBuffer = Space(MAX_PATH * 2)
     
    'Find the file
    lResult = SearchTreeForFile(RootPath, FileName, sBuffer)
     
    If lResult Then 'Trim null, if exists
        lNullPos = InStr(sBuffer, vbNullChar)
        If Not lNullPos Then
            sBuffer = Left(sBuffer, lNullPos - 1)
        End If
        FindFile = sBuffer 'Return filename
    Else
        FindFile = vbNullString 'Nothing found
    End If
     
    Exit Function
     
FileFind_Error:
    FindFile = vbNullString
     
End Function

******PLACE THIS CODE IN A FORM******

Option Explicit

Dim sCheckIt As String, sDrive As String, sFile As String

Private Sub Command1_Click()
    sDrive = "c:\" ' <= Change this or let user choose
    sFile = "comlog.txt" ' <= Change this or let user choose
    sCheckIt = FindFile(sDrive, sFile)

    If sCheckIt = "" Then
        MsgBox "File not found"
    Else
        Debug.Print sCheckIt
    End If
End Sub
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13739268
I just replaced the msvcrt.dll with a new one, which imagehlp.dll depends on, I then ran a file search on an alternate drive 'D:\".  I placed a file in a subfolder, and ran the example.  The result was correct and it found the file in the subfolder correctly, and without crashing VB6.  
I then had it try to find the same file in the C:\ drive (my system drive) and it is back to crashing again.

The exception I receive is "An exception 'Unhandled Win32 Exception' has occurred in VB6.exe"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:anthonywjones66
ID: 13739530
What operating system are you using?

Make MAX_PATH much bigger say 2000,  I'm pretty sure you can now get paths bigger than 260 characters long.

Anthony.
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13739658
Just as it says in the topic,  I'm using Windows XP Pro.

I changed the MAX_PATH to 2000, and VB6 is still crashing on the C:\ drive.
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13739732
I think it's kind of odd that it will search fine in my alternate drive D: and crash in drive C:, which C: is my system drive.

However, VB6 used to crash searching through drive D: before I swapped msvcrt.dll with a new one.

What do you think?
0
 
LVL 8

Assisted Solution

by:anthonywjones66
anthonywjones66 earned 100 total points
ID: 13739884
Well if you look at the current documentation on MSDN for this API call it's not defined in IMAGEHLP.dll at all but in dbghelp.dll.  You might try switching the declare to use that instead.  It states that 2000 or XP is required for this though.  Since that is what you are using try it.

Anthony,
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13740470
Yeah, I see what your saying.  It is bizaar.  Every SearchTreeForFile example made by various people use the imagehlp.dll over the dbghelp.dll.  I replaced the imagehlp.dll with the dbghelp.dll for the SearchTreeForFile library reference, and the results are still the same.  It's interesting to know that either dll works.  

I'm searching for the dbghelp.h file right at the moment, so far it has only found one reference which is placed in my .NET directory.  I'm wondering if this file is missing in the system directory.  But I would think that if it is required by any means, then it would not make sense that the D:\ drive search would be successful.  I would think that none of the drives would be successfully searched.  I wonder if there are other required dependency files for dbghelp.dll to operate properly, and if so, is one of the dependency files corrupt?

Very perplexing...

0
 
LVL 28

Accepted Solution

by:
Ark earned 900 total points
ID: 13742760
This seems to be NT bug for this function: searching at ANY location is OK except of c: root (c:\windows for example is OK) because (IMHO) root directory contain virtual pagefile.sys
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13742840
Yes, I agree Ark, it is quite possible that this is a bug.
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13742842
are you receiving the same symptoms?
0
 
LVL 8

Expert Comment

by:anthonywjones66
ID: 13744707
You test that by placing an additional pagefile on D: and see if you now get a problem on D: also.

Anthony.
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13745793
It may not be only the pagefile.sys.  

Here is what I've done so far as a workaround:
I modified my code to work around the C:\ drive, which is my system drive that contains the pagefile.sys, by not allowing SearchTreeForFile to search the root drive.  Instead, the Dir() function now searches the root drive.  Then, I have the Dir() function in a loop to grab every subdirectory from the root drive, which then SearchTreeForFile will search through every folder and file of each subdirectory until there are no more subdirectories to search in the root drive.

It all worked fine until VB6 crashed somewhere within the 'My Documents' directory from the SearchTreeForFile function.  I then put a windows search to find pagefile.sys anywhere in the C:\ drive.  It came up with only pagefile.sys in c:\ root drive.  I'm going to test some more, and keep y'all posted.  

0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13746169
ok, it appears that there is also a limit to the size of the each directory when SearchTreeForFile is searching through the drive.  I pinpointed the 'Documents and Settings' issue, which was crashing VB6, to be a subdirectory that was over 75 characters in length.  When I changed it to be 75 characters or less, the SearchTreeForFile ran properly.

0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13746238
Also, if you look at paragraph three under the Remarks section in the following link, I think you'll see some similarities about the stipulations with the findfirstfile function compared to the symptoms with the SearchTreeForFile function.

I did try the C:\*, and it doesn't work for SearchTreeForFile, so I thought I would go ahead and let you know before you waiste your time on it.  Using the asterisk is a difference between the two functions, but it may be more than coincidental that neither function can use the C:\ root, unless FindFirstFile uses the asterisk.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp
0
 
LVL 1

Author Comment

by:Drumsticks
ID: 13746262
Thank you both for you assistance.  
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 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