Physical drive size
-
If the file system is corrupt then it is unlikely that any of the normal functions will work successfully, you should try to reformat the device.
Use the best guess
-
But we nothing to do with file system, need to get physical disk size. Many other software are showing correct size for same memory card. Can you please give any idea?
-
Below is WMI call
VariantClear(&vtProp);
hr = pclsObj->Get(L"Size", 0, &vtProp, 0, 0);Below is IOCTL call
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/OCloseHandle(hDevice);
ULONGLONG DiskSize = 0; // size of the drive, in bytes
DiskSize = pdg->Cylinders.QuadPart * (ULONG)pdg->TracksPerCylinder *
(ULONG)pdg->SectorsPerTrack * (ULONG)pdg->BytesPerSector;
wprintf(L"Disk size = %I64d (Bytes)\n"
L" = %.2f (Gb)\n",
DiskSize, (double) DiskSize / (1024 * 1024 * 1024));But both gives same result. pdg->Cylinders.QuadPart is coming 1.
-
I tried IOCTL
DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
ULONGLONG siize = gli.Length.QuadPart;It gives correct result on VS2008 but not on VS2003. I need to code for VS2003. Please guide...
The VS version should make no difference for device IO control API functions. But
IOCTL_DISK_GET_LENGTH_INFO
requires XP or later. To support older Windows versions useIOCTL_DISK_GET_PARTITION_INFO
. -
I tried IOCTL
DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
ULONGLONG siize = gli.Length.QuadPart;It gives correct result on VS2008 but not on VS2003. I need to code for VS2003. Please guide...
-
The VS version should make no difference for device IO control API functions. But
IOCTL_DISK_GET_LENGTH_INFO
requires XP or later. To support older Windows versions useIOCTL_DISK_GET_PARTITION_INFO
. -
I have a memory card which is having corrupted file system. I need to get physical drive size. I tried using WMI but it gives 8 MB only even though its size is 30GB. Can you please guide me?
you have a 30GB memory card? that's a strange size... they're sized in generally powers of two.
-
But why it is not giving correct result on my machine win7+vs2003 but working fine with win7+vs2008. I can not use vs2008 simply because whole product is in vs2003 and need to make correction in same. please suggest solution...
I don't know why.
DeviceIoControl()
is a Windows kernel function that passes the request to the device specific driver. So there should be no differences on one machine when calling this from a VS 2003 or VS 2008 generated application or even any other programming language. -
you have a 30GB memory card? that's a strange size... they're sized in generally powers of two.