Article # 208, added by Geoworks, historical record
| first | previous | index | next | last |

Why FileEnum returns non-zero but invalid handle



FileEnum normally returns the number of files matched as a return value.
Therefore a return of zero means no matches found. You would think that
you could check for non-zero return value to signal that some files where
found. However this isn't quite so. The one time that FileEnum returns
non-zero on failure is when an error occured during the search.  If an
error occurs during the search, FileEnum returns -1. Because of this, 
you cannot assume that a non-zero return value equates to files being 
found; you must check if the returned value is -1.

Usually, you will come across this quirk by getting a Death due to 
ILLEGAL_HANDLE after calling FileEnum. On failure, FileEnum returned
a non-zero value along with a null memory handle.