A breif play around with the APIs led to this
Code:
#include <windows.h>
//Because I have an old version of the SDK on this com..
//...I have to define this stuff
typedef struct _DISK_GEOMETRY_EX {
DISK_GEOMETRY Geometry;
LARGE_INTEGER DiskSize;
BYTE Data[1];
} DISK_GEOMETRY_EX;
#define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX \
CTL_CODE(IOCTL_DISK_BASE, 0x0028, \
METHOD_BUFFERED, FILE_ANY_ACCESS)
//End definitions
int main()
{
DISK_GEOMETRY_EX gde = {0};
DWORD dwDummy;
char szBuff[50];
HANDLE hDisk = CreateFile("\\\\.\\PHYSICALDRIVE0",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hDisk == INVALID_HANDLE_VALUE)
{
MessageBox(0,"Unable to get Handle",0,MB_OK);
return 1;
}
if(DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
0,0,&gde,sizeof(gde),&dwDummy,0))
{
wsprintf(szBuff,"Number of bytes on disk - %I64d",gde.DiskSize);
MessageBox(0,szBuff,"",MB_OK);
}
else
{
MessageBox(0,"Unable to communicate with device",0,MB_OK);
}
CloseHandle(hDisk);
return 0;
}
This should work for Windows XP...and maybe Windows 2000 as well...unfortunately I cant test it properly as none of my disks has more than 1 partition at the moment....but if that isnt the proper call, I guess you could achivie this a similar way