K
ich habe das Problem schon gelöst. Das ist die Version die Funktioniert:
bool USBStick::checkMemory()
{
DISK_GEOMETRY pdg; // disk drive geometry structure
HANDLE hDevice = INVALID_HANDLE_VALUE; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
ULONGLONG DiskSize; // size of the drive, in bytes
char driveL[10] = "\\\\.\\";
TCHAR path[10] ;
TCHAR pathT[4] ;
ULARGE_INTEGER freeBytesAvailable, totalNumberOfBytes,totalNumberOfFreeBytes;//ULARGE_INTEGER
P_GDFSE pGetDiskFreeSpaceEx = NULL;
//Get a path to a USB stick
strncat(driveL,driveLetter,4);
MultiByteToWideChar(CP_ACP,0,driveL,-1,path,sizeof(path));
//Open a USB stick
hDevice = CreateFile(path, // path to the USB stick
GENERIC_READ, // no access to the drive
FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
0); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
printf("CreateFile() faild, error %d\n",GetLastError());
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
&pdg,
sizeof(pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
CloseHandle(hDevice);
if (bResult)
{
DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Gb)\n", DiskSize,
DiskSize / (1024 * 1024 * 1024));
}
else
{
printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError ());
}
MultiByteToWideChar(CP_ACP,0,driveLetter,-1,pathT,sizeof(pathT));
bResult = GetDiskFreeSpaceEx(pathT,(PULARGE_INTEGER)&freeBytesAvailable,(PULARGE_INTEGER)&totalNumberOfBytes,(PULARGE_INTEGER) &totalNumberOfFreeBytes);
if(bResult){
printf("%I64d B\n",freeBytesAvailable);
printf("%I64d B\n",totalNumberOfBytes);
printf("%I64d B\n",totalNumberOfFreeBytes);
printf("%I64d MB\n",((totalNumberOfFreeBytes.QuadPart/(1024*1024)) - record));
if(((totalNumberOfFreeBytes.QuadPart/(1024*1024)) - record) > 0){
return true;
}else{
return false;
}
}
}