I’m writing a function that should find a file.
WIN32_FIND_DATAA* data;
HANDLE handle = FindFirstFile(name,data);//Access violation at address 76FC2373 in module 'ntdll.dll'. Write of address 00000008.
while(handle!= INVALID_HANDLE_VALUE)
{
FindNextFile(handle,data);
result.push_back(data->cFileName);
if(GetLastError())
break;
}
FindClose(handle);
free(data);
I’m doing something wrong?
The FindFirstFile function expects the address of a WIN32_FIND_DATA structure. You were merely passing the value of an uninitiated pointer. It should be:
Be sure to remove the
free(data);line as well (asdatahas not been allocated on the heap).In addition, your current loop will skip the first file. You should use something like: