Another example. I've been getting my winAPI calls to work pretty much the first time (quite lucky). I've got a recursive directory walk that I stole from codeproject.com.
The code below produces this. I have since figured out that the 2 consecutive bottom while printfs are occurring from recursion.
You'll also notice I'm checking directory via && 0x10 as the predefined FILE ATTRIBUTES field shows as undefined. What header is it in?
FrunCB routine address 1392770
FindFirstFile E:\WindowsImageBackup\*
dpath E:\WindowsImageBackup\
NEXT dpath after FNF E:\WindowsImageBackup\
NEXT file/dir ..
NEXT dpath bottom while E:\WindowsImageBackup\
NEXT dpath after FNF E:\WindowsImageBackup\
NEXT file/dir JIM-GLH_2011-11-06_012348
NEXT dpath prior E:\WindowsImageBackup\
NEXT directory
Frun recurse E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348
FrunCB routine address 1392790
FindFirstFile E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\*
dpath E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\
NEXT file/dir ..
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\
NEXT file/dir Backup 2011-11-06 012348
NEXT dpath prior E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\
NEXT directory
Frun recurse E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348
FrunCB routine address 1392790
FindFirstFile E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\*
dpath E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir ..
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_AdditionalFilesc3b9f3c7-5e52-4d5e-8b20-19adc95a34c7.x
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Components.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_RegistryExcludes.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writer4dc3bdd4-ab48-4d07-adb0-3bee2926fd7f.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writer542da469-d3e1-473c-9f4f-7847f01fc64f.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writera6ad56c2-b509-4e6c-bb19-49d8f43532f0.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writerafbab4a2-367d-4d15-a586-71dbb18f8485.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writerbe000cbe-11fe-4426-9c58-531aa6355fc4.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writercd3f2362-8bef-46c7-9181-d62844cdc0b2.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 8ba1faea-ef34-40e0-a9e1-788ab5618fac_Writere8132975-6f93-4464-a53e-1050253ae220.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\8ba1faea-ef34-40e0-a9e1-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 936b54bf-228a-11df-8147-806e6f6e6963.vhd
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\936b54bf-228a-11df-8147-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir 936b54c0-228a-11df-8147-806e6f6e6963.vhd
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\936b54c0-228a-11df-8147-
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
NEXT file/dir BackupSpecs.xml
print2 E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\BackupSpecs.xml
NEXT dpath after file E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
***NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348\
while exhausted
***NEXT dpath bottom while E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348 (trailing backslash has been removed magically)
NEXT dpath after FNF E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348
NEXT file/dir Catalog
NEXT dpath prior E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348
NEXT directory
Frun recurse E:\WindowsImageBackup\JIM-GLH_2011-11-06_012348\Backup 2011-11-06 012348Catalog
Code:
int Frun (TCHAR* Fruni, void (*FrunCB)(TCHAR* FrunCBt)) {
WIN32_FIND_DATA SFrun;
HANDLE HFrun;
TCHAR Frundpath[555];
TCHAR Frunfpath[555];
nl(2);
printf("FrunCB routine address %x", FrunCB); nl(1);
// dpath has \* on the end for use in FindFirstFile calls
_tcscpy (Frundpath, Fruni);
_tcscat (Frundpath, L"\\*");
// fpath has \ on end for discrete use
_tcscpy (Frunfpath, Fruni);
_tcscat (Frunfpath, L"\\");
// find first file/directory and set Handle
// dpath has \*
_tprintf(L"FindFirstFile %s", Frundpath); nl(1);
HFrun = FindFirstFile(Frundpath, &SFrun);
// remove ending *
_tcscpy (Frundpath, Frunfpath);
_tprintf(L"dpath %s", Frundpath); nl(1);
// skip . ..
if ( SFrun.cFileName[0] != L'.' ) {
// directory?
if ( SFrun.dwFileAttributes & 0x10 ) {
_tprintf(L"FIRST dpath prior %s", Frundpath); nl(1);
_tcscat (Frundpath, SFrun.cFileName);
_tprintf(L"FIRST directory\nFrun recurse %s", Frundpath); nl(1);
Frun(Frundpath, print2);
}
// file
else {
_tcscpy (Frunfpath, Frundpath);
_tcscat (Frunfpath, SFrun.cFileName);
FrunCB(Frunfpath);
_tprintf(L"FIRST dpath after file %s", Frundpath); nl(1);
}
}
// get each file/directory
while ( FindNextFile (HFrun, &SFrun) ) {
_tprintf(L"NEXT dpath after FNF %s", Frundpath); nl(1);
_tprintf(L"NEXT file/dir %s", SFrun.cFileName); nl(1);
// skip . ..
if ( SFrun.cFileName[0] != L'.' ) {
// directory?
if ( SFrun.dwFileAttributes & 0x10 ) {
_tprintf(L"NEXT dpath prior %s", Frundpath); nl(1);
_tcscat (Frundpath, SFrun.cFileName);
_tprintf(L"NEXT directory\nFrun recurse %s", Frundpath); nl(1);
Frun(Frundpath, print2);
}
// file
else {
_tcscpy (Frunfpath, Frundpath);
_tcscat (Frunfpath, SFrun.cFileName);
FrunCB(Frunfpath);
_tprintf(L"NEXT dpath after file %s", Frundpath); nl(1);
}
// . ..
}
_tprintf(L"NEXT dpath bottom while %s", Frundpath); nl(1);
// while
}
printf("while exhausted\n");
FindClose(HFind);
return(-1);
}