FindVolumeClose(), FindFirstVolume(), GetVolumeInformation()
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Target platform: none, just for learning
Header file: Standard and Windows
Additional library: Windows Platform SDK
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: non-CLR or unmanaged
To do: More on Windows volume management
To show: Using FindVolumeClose(), FindFirstVolume(), GetVolumeInformation() functions
// Target for Win Xp
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>
#define BUFSIZE MAX_PATH
#define FILESYSNAMEBUFSIZE MAX_PATH
// You may want to try wmain()
int main(void)
{
// buffer for unique volume identifiers
char buf[BUFSIZE];
DWORD lpMaximumComponentLength;
// flags that describe the file system
DWORD dwSysFlags;
char FileSysNameBuf[FILESYSNAMEBUFSIZE];
BOOL test;
// handle for the volume search
HANDLE hVol;
// Open a scan for volumes.
hVol = FindFirstVolume((LPWSTR)buf, BUFSIZE);
if(hVol == INVALID_HANDLE_VALUE)
{
printf ("No volumes found!\n");
return (1);
}
// If all the requested information is retrieved, the return value is nonzero.
// If not all the requested information is retrieved, the return value is 0 (zero).
test = GetVolumeInformation(
(LPCWSTR)buf,
NULL,
BUFSIZE,
NULL,
&lpMaximumComponentLength,
&dwSysFlags,
(LPWSTR)FileSysNameBuf,
FILESYSNAMEBUFSIZE
);
printf("The GetVolumeInformation() return value is: %d\n", test);
printf("The first volume found: %S\n", buf);
printf("The buffer for volume name: %d\n", BUFSIZE);
printf("The max component length: %d\n", lpMaximumComponentLength);
printf("The file system flag: %d\n", dwSysFlags);
printf("The file system: %S\n", FileSysNameBuf);
printf("The buffer for file system name: %d\n", FILESYSNAMEBUFSIZE);
if(FindVolumeClose(hVol) != 0)
printf("Handle for the %S closed successfully!\n", buf);
else
printf("%S handle failed to close!\n");
return 0;
}
Output example:
The GetVolumeInformation() return value is: 1
The first volume found: \\?\Volume{4039899d-f63b-11d9-9648-806d6172696f}\
The buffer for volume name: 260
The max component length: 255
The file system flag: 459007
The file system: NTFS
The buffer for file system name: 260
Handle for the \\?\Volume{4039899d-f63b-11d9-9648-806d6172696f}\ closed successfully!
Press any key to continue . . .