Win32 API 日本語リファレンス
ホームUI.Shell › DriveType

DriveType

関数
指定ドライブの種類を取得する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

INT DriveType(
    INT iDrive
);

パラメーター

名前方向説明
iDriveINTinテストするドライブの番号。"A:" が 0、"B:" が 1 に対応し、以降も同様です。

戻り値の型: INT

公式ドキュメント

DriveType 関数は、ドライブ番号に基づいてドライブの種類を判定します。(DriveType 関数)

戻り値

型: int

次のいずれかの値を返します。

戻り値 説明
DRIVE_UNKNOWN
ドライブの種類を判定できません。
DRIVE_NO_ROOT_DIR
ルートパスが無効です。たとえば、そのパスにボリュームがマウントされていません。
DRIVE_REMOVABLE
ディスクをドライブから取り外すことができます。
DRIVE_FIXED
ディスクをドライブから取り外すことができません。
DRIVE_REMOTE
ドライブはリモート (ネットワーク) ドライブです。
DRIVE_CDROM
ドライブは CD-ROM ドライブです。
DRIVE_RAMDISK
ドライブは RAM ディスクです。

解説(Remarks)

DriveTypeRealDriveType を呼び出すのと同等です。RealDriveType の使用が推奨されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

INT DriveType(
    INT iDrive
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int DriveType(
    int iDrive   // INT
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function DriveType(
    iDrive As Integer   ' INT
) As Integer
End Function
' iDrive : INT
Declare PtrSafe Function DriveType Lib "shell32" ( _
    ByVal iDrive As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DriveType = ctypes.windll.shell32.DriveType
DriveType.restype = ctypes.c_int
DriveType.argtypes = [
    ctypes.c_int,  # iDrive : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
DriveType = Fiddle::Function.new(
  lib['DriveType'],
  [
    Fiddle::TYPE_INT,  # iDrive : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn DriveType(
        iDrive: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int DriveType(int iDrive);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DriveType' -Namespace Win32 -PassThru
# $api::DriveType(iDrive)
#uselib "SHELL32.dll"
#func global DriveType "DriveType" sptr
; DriveType iDrive   ; 戻り値は stat
; iDrive : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global DriveType "DriveType" int
; res = DriveType(iDrive)
; iDrive : INT -> "int"
; INT DriveType(INT iDrive)
#uselib "SHELL32.dll"
#cfunc global DriveType "DriveType" int
; res = DriveType(iDrive)
; iDrive : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procDriveType = shell32.NewProc("DriveType")
)

// iDrive (INT)
r1, _, err := procDriveType.Call(
	uintptr(iDrive),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function DriveType(
  iDrive: Integer   // INT
): Integer; stdcall;
  external 'SHELL32.dll' name 'DriveType';
result := DllCall("SHELL32\DriveType"
    , "Int", iDrive   ; INT
    , "Int")   ; return: INT
●DriveType(iDrive) = DLL("SHELL32.dll", "int DriveType(int)")
# 呼び出し: DriveType(iDrive)
# iDrive : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shell32" fn DriveType(
    iDrive: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
proc DriveType(
    iDrive: int32  # INT
): int32 {.importc: "DriveType", stdcall, dynlib: "SHELL32.dll".}
pragma(lib, "shell32");
extern(Windows)
int DriveType(
    int iDrive   // INT
);
ccall((:DriveType, "SHELL32.dll"), stdcall, Int32,
      (Int32,),
      iDrive)
# iDrive : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DriveType(
    int32_t iDrive);
]]
local shell32 = ffi.load("shell32")
-- shell32.DriveType(iDrive)
-- iDrive : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const DriveType = lib.func('__stdcall', 'DriveType', 'int32_t', ['int32_t']);
// DriveType(iDrive)
// iDrive : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHELL32.dll", {
  DriveType: { parameters: ["i32"], result: "i32" },
});
// lib.symbols.DriveType(iDrive)
// iDrive : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DriveType(
    int32_t iDrive);
C, "SHELL32.dll");
// $ffi->DriveType(iDrive);
// iDrive : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Shell32 extends StdCallLibrary {
    Shell32 INSTANCE = Native.load("shell32", Shell32.class);
    int DriveType(
        int iDrive   // INT
    );
}
@[Link("shell32")]
lib LibSHELL32
  fun DriveType = DriveType(
    iDrive : Int32   # INT
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DriveTypeNative = Int32 Function(Int32);
typedef DriveTypeDart = int Function(int);
final DriveType = DynamicLibrary.open('SHELL32.dll')
    .lookupFunction<DriveTypeNative, DriveTypeDart>('DriveType');
// iDrive : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DriveType(
  iDrive: Integer   // INT
): Integer; stdcall;
  external 'SHELL32.dll' name 'DriveType';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DriveType"
  c_DriveType :: Int32 -> IO Int32
-- iDrive : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drivetype =
  foreign "DriveType"
    (int32_t @-> returning int32_t)
(* iDrive : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)

(cffi:defcfun ("DriveType" drive-type :convention :stdcall) :int32
  (i-drive :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DriveType = Win32::API::More->new('SHELL32',
    'int DriveType(int iDrive)');
# my $ret = $DriveType->Call($iDrive);
# iDrive : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目