Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,055 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,603 people online right now. Registration is fast and FREE... Join Now!




querydosdevice question

 
Reply to this topicStart new topic

querydosdevice question

tootypegs
5 Aug, 2008 - 09:42 AM
Post #1

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
hi, could anyone help me out im having major problems trying to use the querydosdevice() function. I am trying to use this function to help me match each drive letter to its physical device number but so far Im just not having any look using it. Ive looked at msdn and even from its examples and docuemtnation i can get anything basic to compile that just prints the data out in a command line app.

I would really appreciate some advice

thank you
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Querydosdevice Question
5 Aug, 2008 - 01:34 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
I have not done any debugging really but it seems to work for me (Dev-C++ 4.9.9.something).
cpp
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>

int main() {
char DeviceName[256]="";
char VolumeName[256]="";
char FileSystemName[256]="";
HANDLE handle;
BOOL flag = TRUE;
BOOL gotInfo = FALSE;
long SerialNumber;

handle = FindFirstVolumeA((LPCSTR)DeviceName, 256);
if (handle != INVALID_HANDLE_VALUE) {
flag = TRUE;
do {
gotInfo = GetVolumeInformationA((LPCSTR)DeviceName, VolumeName, 256, &SerialNumber, NULL, NULL, FileSystemName, 256 );
printf("DeviceName: %s\n", DeviceName);
if (gotInfo) {
printf(" VolumeName: %s\t SerialNumber: %X\n", VolumeName, SerialNumber);
} else {
puts(" No Info Returned...\n");
}
flag = FindNextVolumeA(handle, (LPCSTR)DeviceName, 256);
} while (flag == TRUE);
FindVolumeClose(handle);
}
system("pause");
return 0;
}

User is offlineProfile CardPM
+Quote Post

tootypegs
RE: Querydosdevice Question
5 Aug, 2008 - 02:26 PM
Post #3

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
hi there, thank you for you reply I appreciate it and il try it straight away. ive had a go with something similar that i found on msdn which i think may be what im looking for aswell but im having a problem declaring the DISK_GEOMETRY variable as i seem to be getting errors regarding this variable.

CODE

#include <windows.h>
#include <winioctl.h>
#include <stdio.h>

int main()
{

HANDLE hDevice;               // handle to the drive to be examined
  BOOL bResult;                 // results flag
  DWORD junk;                   // discard results

  hDevice = CreateFile(TEXT("\\\\.\\PhysicalDrive0"),  // drive
                    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);
  }




DISK_GEOMETRY pdg;
ULONGLONG DiskSize;

  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



    printf("Cylinders = %I64d\n", pdg.Cylinders);
    printf("Tracks/cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
    printf("Sectors/track = %ld\n", (ULONG) pdg.SectorsPerTrack);
    printf("Bytes/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 (Gb)\n", DiskSize,
           DiskSize / (1024 * 1024 * 1024));



}


User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Querydosdevice Question
5 Aug, 2008 - 04:35 PM
Post #4

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
There aren't any special ifdefs that I can see in winioctl.h (which is where DISK_GEOMETRY is defined). So that might indicate one of the following:

1.) Your winioctl.h isn't complete (depending on what headers you're using, especially with Cygwin).
2.) Your winioctl.h does have special ifdefs that aren't present in MinGWs or the copy of the Windows 2003 Platform SDK that I have.
3.) There is a problem up farther in the line that is causing the error that you're seeing.
User is offlineProfile CardPM
+Quote Post

tootypegs
RE: Querydosdevice Question
6 Aug, 2008 - 03:43 AM
Post #5

D.I.C Head
**

Joined: 9 Oct, 2007
Posts: 177


My Contributions
Thanks for the input, i have a feeling my problem is the last of the options and its deeper in my code.
ive been tinkering a bit more and it seems now that the error lies with the line

CODE

pdg, sizeof(*pdg)


errors: Not allowed type in function main?
Operator not implimented in type _DISK_GEOMETrY for arguments of the same type in main

I think solving this could solve my problem
User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Querydosdevice Question
6 Aug, 2008 - 02:25 PM
Post #6

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
I'm guessing that you meant to use:

&pdg, sizeof(pdg)

as opposed to pdg, sizeof(*pdg). DISK_GEOMETRY is not a pointer type.

( This probably won't help the type definition problem, as the type definition is above the erroneous code, not below it. Plus, it's not a syntax error that affects the structure of the program. )
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:56PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month