www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Trouble compiling Microsoft example code

reply John Seger <John_member pathlink.com> writes:
I'm getting a bunch of error messages trying to compile an example program from
Microsoft. All error messages relate to casts. I've included the error messages
here followed by the source code. Compiler version 8.33. 

D:\> dmc GetDriveGeom.c
printf("Tracks per cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
^
GetDriveGeom.c(50) : Error: need explicit cast for function parameter 2 to get
from: unsigned long
to  : union _LARGE_INTEGER
printf("Sectors per track = %ld\n", (ULONG) pdg.SectorsPerTrack);
^
GetDriveGeom.c(51) : Error: need explicit cast for function parameter 2 to get
from: unsigned long
to  : union _LARGE_INTEGER
printf("Bytes per sector = %ld\n", (ULONG) pdg.BytesPerSector);
^
GetDriveGeom.c(52) : Error: need explicit cast for function parameter 2 to get
from: unsigned long
to  : union _LARGE_INTEGER
DiskSize / (1024 * 1024));
^
GetDriveGeom.c(57) : Error: need explicit cast for function parameter 2 to get
from: uns long long
to  : union _LARGE_INTEGER
printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError ());
^
GetDriveGeom.c(61) : Error: need explicit cast for function parameter 2 to get
Fatal error: too many errors
--- errorlevel 1
---------------------------------- Source Code ---------------------------
#include <windows.h>
#include <winioctl.h>

BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice;               // handle to the drive to be examined
BOOL bResult;                 // results flag
DWORD junk;                   // discard results

hDevice = CreateFile("\\\\.\\PhysicalDrive0",  // drive to open
0,                // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL,             // default security attributes
OPEN_EXISTING,    // disposition
0,                // file attributes
NULL);            // do not copy file attributes

if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
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);

return (bResult);
}

int main(int argc, char *argv[])
{
DISK_GEOMETRY pdg;            // disk drive geometry structure
BOOL bResult;                 // generic results flag
ULONGLONG DiskSize;           // size of the drive, in bytes

bResult = GetDriveGeometry (&pdg);

if (bResult)
{
printf("Cylinders = %I64d\n", pdg.Cylinders);
printf("Tracks per cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
printf("Sectors per track = %ld\n", (ULONG) pdg.SectorsPerTrack);
printf("Bytes per sector = %ld\n", (ULONG) pdg.BytesPerSector);

DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Mb)\n", DiskSize,
DiskSize / (1024 * 1024));
}
else
{
printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError ());
}

return ((int)bResult);
}
May 30 2003
parent John Seger <John_member pathlink.com> writes:
Got it! Just needed a few tweaks. Didn't need all the explicit casts ... made a
couple of minor changes and it works.


In article <bb90cb$52p$1 digitaldaemon.com>, John Seger says...
I'm getting a bunch of error messages trying to compile an example program from
Microsoft. All error messages relate to casts. I've included the error messages
here followed by the source code. Compiler version 8.33. 

May 30 2003