_getdrives

返回一个位掩码表示现在可用的磁盘驱动器。

重要

此 API 不能用于在 Windows 运行时 中执行的应用程序。有关更多信息,请参见不支持 /ZW 的 CRT 函数

unsigned long _getdrives( void );

返回值

如果函数成功,返回值是一个代表了当前可用的磁盘驱动器的位掩码。 数位位置 0 (最低有效位) 是驱动器A,数位位置 1 是驱动器 B,数位位置 2 是驱动器 C,依此类推。 如果函数失败,则返回值为 0。 若要获取扩展的错误信息,请调用 GetLastError。

要求

例程

必需的标头

_getdrives

<direct.h>

有关更多兼容性信息,请参见兼容性

示例

// crt_getdrives.c
// This program retrives and lists out
// all the logical drives that are 
// currently mounted on the machine.

#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szDrvMsg[] = _T("A:\n");

int main(int argc, char* argv[]) {
   ULONG uDriveMask = _getdrives();

   if (uDriveMask == 0)
   {
      printf( "_getdrives() failed with failure code: %d\n",
              GetLastError());
   }
   else
   {
      printf("The following logical drives are being used:\n");

      while (uDriveMask) {
         if (uDriveMask & 1)
            printf(g_szDrvMsg);

         ++g_szDrvMsg[0];
         uDriveMask >>= 1;
      }
   }
}
  

.NET Framework Equivalent

不适用。 若要调用标准 C 函数,请使用 PInvoke。 有关详细信息,请参阅平台调用示例

请参见

参考

目录控制