我编写了一个小程序,它将搜索我 PC 中的所有逻辑驱动器,然后将它们打印出来。但与我的预期不同,它没有显示它们.. 这是我的代码示例
TCHAR szDrive[] = (" A:");
DWORD drive = GetLogicalDrives();
printf("The bitmask of the logical drives in hex: %0X\n", drive);
printf("The bitmask of the logical drives in decimal: %d\n", drive);
if(drive == 0)
printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError());
else
{
printf("This machine has the following logical drives:\n");
while(drive)
{
// Use the bitwise AND, 1â€"available, 0-not available
if(drive & 1)
printf("%S ", (const char *)szDrive);
// increment, check next drive
++szDrive[1];
// shift the bitmask binary right
drive >>= 1;
}
printf("\n ");
}