Share via


_getdrives

傳回代表目前可用之磁碟機的位元遮罩。

重要

這個 API 不能用於在 Windows 執行階段中執行的應用程式。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。

語法

unsigned long _getdrives( void );

傳回值

如果此函式成功,則傳回值為代表目前可用之磁碟機的位元遮罩。 位位置 0 (最小有效位) 代表磁片磁碟機 A。同樣地,位位置 1 代表磁片磁碟機 B、位位置 2 代表磁片磁碟機 C 等等。 如果此函式失敗,則傳回值為零。 若要取得延伸錯誤資訊,請呼叫 GetLastError

備註

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
_getdrives <direct.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_getdrives.c
// This program retrieves 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;
      }
   }
}
The following logical drives are being used:
A:
C:
D:
E:

另請參閱

目錄控制項