FindNextFile exception

Hello guys!

i'm trying to display all contents of the "Images" directory

i'm studying this msdn page : https://msdn.microsoft.com/en-us/library/aa364428(VS.85).aspx and https://msdn.microsoft.com/it-it/library/windows/desktop/aa365200(v=vs.85).aspx

now i've this code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
WIN32_FIND_DATA FindFileData;
		HANDLE hFind = INVALID_HANDLE_VALUE;
		LARGE_INTEGER FileSize;
		TCHAR Img[MAX_PATH];
		DWORD dwError;
		bool result;

		SUCCEEDED(SHGetFolderPath(NULL, CSIDL_MYPICTURES | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, Img));
		cout << "Scanning : " << Img;
		hFind = FindFirstFile(Img,&FindFileData);
		if (hFind == INVALID_HANDLE_VALUE)
		{
			printf("FindFirstFile failed (%d)\n", GetLastError());
			return;
		}
		else
		{
			_tprintf(TEXT("The first file found is %s\n"),FindFileData.cFileName);
			FindClose(hFind);
		}
		do {
			if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
				_tprintf(TEXT("  %s   <DIR>\n"), FindFileData.cFileName);
			}
			else {
				FileSize.LowPart = FindFileData.nFileSizeLow;
				FileSize.HighPart = FindFileData.nFileSizeHigh;
				_tprintf(TEXT("  %s   %ld bytes\n"), FindFileData.cFileName, FileSize.QuadPart);
			}
			result = FindNextFile(hFind, &FindFileData);

		} while (result);
		dwError = GetLastError();
		if (dwError != ERROR_NO_MORE_FILES) {
			_tprintf(TEXT("FindFirstFile\n"));
		}
		FindClose(hFind);


This compiles good but while testing i get an access violation!
http://i.imgur.com/ZawKAkd.png
Why? Thanks !
Last edited on
You closed you result-structure in 19 FindClose(hFind); line. Remove this line.
Okay, now i haven't got any exception but the output is only:

Scanning : A:\Utenti\Mario\Immagini
The first file found is Immagini
  Immagini   <DIR>

but in A:\Utenti\Mario\Immagini there are really a lot of folders and files
Why aren't shown?
Try to assign A:\Utenti\Mario\Immagini\*.* to Img.
Works! Tnx
Topic archived. No new replies allowed.