I thought I knew what I was doing with this technique, but I must be doing something different this time.
I'm getting an error when I try FindNextFileA by passing parameters.
// "$FndDirEnt_Sbr_Mod.cpp"
#include <stdio.h>
typedef struct {
char SchPth[MAX_PATH]; // Path of directory to search
char DirFilNamFnd[MAX_PATH]; // Name of directory or file found
bool DirFndInd; // Directory was found indicator
bool NrmBitInd; // Normal bit on indicator
bool ArcBitInd; // Archive bit on indicator
bool HidBitInd; // Hidden bit on indicator
bool RdoBitInd; // Read-only bit on indicator
DWORD LstErr; // Error code if not found
}FndFilInfStc;
bool FndFstDirEnt(HANDLE * FndFilHnd, FndFilInfStc * FndFilInf)
;
bool FndNxtDirEnt(HANDLE FndFilHnd, FndFilInfStc * FndFilInf)
;
#include "$FndDirEnt_Sbr_Pub.h"
#define BitFnd(ChkBit, BitChkFor) ((ChkBit & BitChkFor) == BitChkFor)
void FndDirEnt()
{
HANDLE FndFilHnd;
FndFilInfStc FndFilInf;
bool FndDirErr;
strncpy_s(FndFilInf.SchPth, sizeof(FndFilInf.SchPth), "C:\\*.*", strlen("C:\\*.*"));
FndDirErr = FndFstDirEnt(&FndFilHnd, &FndFilInf);
if (FndDirErr)
FndDirErr = FndNxtDirEnt(&FndFilHnd, &FndFilInf);
}
bool FndFstDirEnt(HANDLE * FndFilHnd, FndFilInfStc * FndFilInf)
{
LPCSTR lpFileName;
FINDEX_INFO_LEVELS fInfoLevelId = FindExInfoBasic;
LPVOID lpFindFileData;
FINDEX_SEARCH_OPS fSearchOp = FindExSearchNameMatch;
LPVOID lpSearchFilter = NULL;
DWORD dwAdditionalFlags = FIND_FIRST_EX_LARGE_FETCH;
size_t NbrChrCvt = 0;
_WIN32_FIND_DATAA FndFilDta;
*FndFilHnd = INVALID_HANDLE_VALUE;
*FndFilHnd = FindFirstFileExA(FndFilInf->SchPth, fInfoLevelId, &FndFilDta, fSearchOp, lpSearchFilter, dwAdditionalFlags);
if (*FndFilHnd == INVALID_HANDLE_VALUE) {
FndFilInf->LstErr = GetLastError();
printf("Invalid handle for %s\n", FndFilInf->SchPth);
return false; // **************** EARLY RETURN ****************
}
else {
printf("%p\n", FndFilHnd);
return true;
}
}
bool FndNxtDirEnt(HANDLE FndFilHnd, FndFilInfStc * FndFilInf)
{
_WIN32_FIND_DATAA FndFilDta;
bool FndDirErr;
printf("%p schpth=%s\n", FndFilHnd, FndFilInf->SchPth);
FndDirErr = FindNextFileA(FndFilHnd, &FndFilDta); // <-- error here
return FndDirErr;
}
I'm getting the following error:
Exception thrown at 0x00007FFB564D9C90 (ntdll.dll)
in $FndDirEnt_Tst.exe: 0xC0000005: Access violation reading location
0xFFFFFFFFFFFFFFFF.
The output I get is:
00000033228FF078
00000033228FF078 schpth=C:\*.*
I don't know what other details I can add, but I keep getting an error trying to submit the question saying that my post is mostly code. TIA.
Here
FndDirErr = FndNxtDirEnt(&FndFilHnd, &FndFilInf);
you're passing the address of a handle where you should be passing a handle.
The address of a handle is not a valid handle.
Remove the ampersand from &FndFilHnd
.
User contributions licensed under CC BY-SA 3.0