GetDriveType() - finding the drive types

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Target platform: none, just for learning

Header file: Standard and Windows

Additional library: Windows Platform SDK

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: non-CLR or unmanaged

To do: Finding the Windows drive types

To show: Using the GetDriveType() function

 

 

#include <windows.h>

#include <stdio.h>

 

// May use 2-D array for char. This program compiled for wide char/unicode

LPCWSTR drive2[13] = {L"A:\\", L"B:\\", L"C:\\", L"D:\\", L"E:\\", L"F:\\", L"G:\\", L"H:\\",L"I:\\", L"J:\\", L"K:\\", L"L:\\"};

 

// You may want to use the wmain() version

int main(void)

{

int i;

UINT test;

 

for(i=0; i<12; i++)

{

test = GetDriveType(drive2[i]);

switch(test)

{

case 0: printf("Drive %S is type %d - Cannot be determined.\n", drive2[i], test);

break;

case 1: printf("Drive %S is type %d - Invalid root path/Not available.\n", drive2[i], test);

break;

case 2: printf("Drive %S is type %d - Removable.\n", drive2[i], test);

break;

case 3: printf("Drive %S is type %d - Fixed.\n", drive2[i], test);

break;

case 4: printf("Drive %S is type %d - Network.\n", drive2[i], test);

break;

case 5: printf("Drive %S is type %d - CD-ROM.\n", drive2[i], test);

break;

case 6: printf("Drive %S is type %d - RAMDISK.\n", drive2[i], test);

break;

default : "Unknown value!\n";

}

}

return 0;

}

 

Output example:

 

Drive A:\ is type 2 - Removable.

Drive B:\ is type 1 - Invalid root path/Not available.

Drive C:\ is type 3 - Fixed.

Drive D:\ is type 1 - Invalid root path/Not available.

Drive E:\ is type 3 - Fixed.

Drive F:\ is type 3 - Fixed.

Drive G:\ is type 3 - Fixed.

Drive H:\ is type 1 - Invalid root path/Not available.

Drive I:\ is type 1 - Invalid root path/Not available.

Drive J:\ is type 1 - Invalid root path/Not available.

Drive K:\ is type 5 - CD-ROM.

Drive L:\ is type 1 - Invalid root path/Not available.

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index