我需要幫助我的一個程序,它可以提取系統中的可用驅動器並打印有關驅動器的各種信息。我使用的是VC++,對於C++來說相當新穎,需要來自有經驗的程序員的一些高級輸入或示例代碼。GetLogicalDrives加上附加信息C++
這裏是我當前的源代碼:
#include "stdafx.h"
#include Windows.h
#include stdio.h
#include iostream
using namespace std;
int main()
{
// Initial Dummy drive
WCHAR myDrives[] = L" A";
// Get the logical drive bitmask (1st drive at bit position 0, 2nd drive at bit position 1... so on)
DWORD myDrivesBitMask = GetLogicalDrives();
// Verifying the returned drive mask
if(myDrivesBitMask == 0)
wprintf(L"GetLogicalDrives() failed with error code: %d\n", GetLastError());
else {
wprintf(L"This machine has the following logical drives:\n");
while(myDrivesBitMask) {
// Use the bitwise AND with 1 to identify
// whether there is a drive present or not.
if(myDrivesBitMask & 1) {
// Printing out the available drives
wprintf(L"drive %s\n", myDrives);
}
// increment counter for the next available drive.
myDrives[1]++;
// shift the bitmask binary right
myDrivesBitMask >>= 1;
}
wprintf(L"\n");
}
system("pause");
}
` ,尤其是圓形的是輸出 -
This machine has the following logical drives:
drive C
drive D
drive E
drive F
drive G
drive H
drive I
我需要輸出更多的信息有關每個驅動器(可能是一個例子會在更短的時間內講述故事):
驅動器 - C:\ 光驅類型:固定 驅動就緒狀態:真 卷標:引導驅動器 文件系統類型:NTFS 可用空間:30021926912 總驅動器尺寸:240055742464
驅動器 - d: \ 光驅類型:固定 驅動就緒狀態:真 卷標:應用程序數據 文件系統類型:NTFS 可用空間:42462507008 總驅動器尺寸:240054693888
可以使用哪些方法,libs api等來提取驅動器類型,驅動器狀態,卷標,文件系統類型,可用空間和總驅動器大小?
*注意,我注意到我的預處理器指令有問題,特別是在標準I/O頭文件中。我知道這不是推薦的方式使用printf和cout是類型安全和適當的路線,但我不知道如何格式化輸出在cout中,你會在wprintf(L"drive %s\n", myDrives);.... so how would you do this with cout??
在此先感謝。