|
-
Apr 4th, 2004, 12:07 PM
#1
Thread Starter
Lively Member
File Handle Closing
Hey Everyone 
I have a quick question regarding the FindFile API Call, if im doing a recurse, and i do something like this:
VB Code:
lngFileHandle = FindFirstFile(DirectoryString & "*.*", WFD)
and close the handle like this:
VB Code:
lngFileHandle = FindClose(lngFileHandle)
What would happen, if, for whatever reason, the function it was in generated an error and the file handle was never closed. Would this have an adverse affect on my program? On the file? Or on anything related?
Hope anyone can answer this 
Thanks, Gav
-
Apr 4th, 2004, 12:12 PM
#2
Fanatic Member
Why not check handles and close valid ones in your error handler?
-
Apr 4th, 2004, 12:16 PM
#3
Thread Starter
Lively Member
I could do that... i was thinking of something like this:
VB Code:
if lngFileHandle <> 0 then
'Close Handle Here
endif
However, what i really wanted to know, is what would happen if file handles were left unclosed. Also, in the error handler, what would happen if it generated an error closing the file handle? I dont like putting things in error handles that could generate errors (Would this happen?)
Hope that makes sense!
Thanks, Gav
-
Apr 4th, 2004, 12:24 PM
#4
Fanatic Member
FindClose will not raise a VB error.
If you don't close the handles, you'll leak some memory.
-
Apr 4th, 2004, 12:29 PM
#5
Thread Starter
Lively Member
Okay Brilliant 
So, it wont interfere with the actual file itself? It would just leak a bit of memory (because VB has allocated the handle?). I think im gonna close the handle then, is what i suggested for the close handle correct?
Thanks again!
Gav
-
Apr 4th, 2004, 12:47 PM
#6
Fanatic Member
No I'm pretty sure it won't intefere with the file, because you haven't actually opened it.
You should check against INVALID_HANDLE_VALUE for closing:
if handle <> INVALID_HANDLE_VALUE then ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|