Win32 API 日本語リファレンス
ホームStorage.FileSystem › FindFirstVolumeMountPointW

FindFirstVolumeMountPointW

関数
ボリューム上のマウントポイント列挙を開始する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE FindFirstVolumeMountPointW(
    LPCWSTR lpszRootPathName,
    LPWSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);

パラメーター

名前方向説明
lpszRootPathNameLPCWSTRinマウントされたフォルダーを走査する対象ボリュームのボリューム GUID パス。末尾に円記号(バックスラッシュ)が必要です。
lpszVolumeMountPointLPWSTRout最初に見つかったマウントされたフォルダーの名前を受け取るバッファーへのポインター。
cchBufferLengthDWORDinマウントされたフォルダーへのパスを受け取るバッファーの長さ( TCHAR 単位)。

戻り値の型: HANDLE

公式ドキュメント

指定したボリューム上のマウントされたフォルダーの名前を取得します。(Unicode)

戻り値

関数が成功した場合、戻り値は検索ハンドルであり、後続の FindNextVolumeMountPoint および FindVolumeMountPointClose 関数の呼び出しで使用します。

関数がボリューム上のマウントされたフォルダーを見つけられなかった場合、戻り値は INVALID_HANDLE_VALUE エラーコードになります。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

FindFirstVolumeMountPoint 関数は、 マウントされたフォルダーの検索ハンドルを開き、指定したボリューム上で最初に見つかったマウントされたフォルダーに関する情報を返します。検索ハンドルが確立された後は、 FindNextVolumeMountPoint 関数を使用して 他のマウントされたフォルダーを検索できます。検索ハンドルが不要になったら、 FindVolumeMountPointClose 関数で閉じてください。

FindFirstVolumeMountPointFindNextVolumeMountPoint、および FindVolumeMountPointClose の各関数は、 指定したボリュームのマウントされたフォルダーへのパスを返します。これらの関数はドライブ文字やボリューム GUID パスを返しません。ボリュームのボリューム GUID パスを列挙する方法については、 ボリューム GUID パスの列挙を参照してください。

これらの関数によって返されるマウントされたフォルダーの順序と、他の関数やツールによって返されるマウントされたフォルダーの順序との間に、何らかの相関関係があると想定すべきではありません。

Windows 8 および Windows Server 2012 では、この関数は次のテクノロジでサポートされています。

テクノロジ サポート状況
Server Message Block (SMB) 3.0 プロトコル いいえ
SMB 3.0 透過的フェールオーバー (TFO) いいえ
SMB 3.0 スケールアウト ファイル共有 (SO) 対応 いいえ
クラスター共有ボリューム ファイル システム (CsvFS) いいえ
回復性ファイル システム (ReFS) いいえ

SMB はボリューム管理関数をサポートしていません。CsvFS は CSV ボリューム上へのマウント ポイントの追加をサポートしていません。 ReFS はマウント ポイントをインデックス化しません。

メモ

winbase.h ヘッダーは FindFirstVolumeMountPoint を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイル エラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。

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

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE FindFirstVolumeMountPointW(
    LPCWSTR lpszRootPathName,
    LPWSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindFirstVolumeMountPointW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszRootPathName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumeMountPoint,   // LPWSTR out
    uint cchBufferLength   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindFirstVolumeMountPointW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszRootPathName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumeMountPoint As System.Text.StringBuilder,   ' LPWSTR out
    cchBufferLength As UInteger   ' DWORD
) As IntPtr
End Function
' lpszRootPathName : LPCWSTR
' lpszVolumeMountPoint : LPWSTR out
' cchBufferLength : DWORD
Declare PtrSafe Function FindFirstVolumeMountPointW Lib "kernel32" ( _
    ByVal lpszRootPathName As LongPtr, _
    ByVal lpszVolumeMountPoint As LongPtr, _
    ByVal cchBufferLength As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindFirstVolumeMountPointW = ctypes.windll.kernel32.FindFirstVolumeMountPointW
FindFirstVolumeMountPointW.restype = ctypes.c_void_p
FindFirstVolumeMountPointW.argtypes = [
    wintypes.LPCWSTR,  # lpszRootPathName : LPCWSTR
    wintypes.LPWSTR,  # lpszVolumeMountPoint : LPWSTR out
    wintypes.DWORD,  # cchBufferLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FindFirstVolumeMountPointW = Fiddle::Function.new(
  lib['FindFirstVolumeMountPointW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszRootPathName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpszVolumeMountPoint : LPWSTR out
    -Fiddle::TYPE_INT,  # cchBufferLength : DWORD
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn FindFirstVolumeMountPointW(
        lpszRootPathName: *const u16,  // LPCWSTR
        lpszVolumeMountPoint: *mut u16,  // LPWSTR out
        cchBufferLength: u32  // DWORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr FindFirstVolumeMountPointW([MarshalAs(UnmanagedType.LPWStr)] string lpszRootPathName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumeMountPoint, uint cchBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindFirstVolumeMountPointW' -Namespace Win32 -PassThru
# $api::FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
#uselib "KERNEL32.dll"
#func global FindFirstVolumeMountPointW "FindFirstVolumeMountPointW" wptr, wptr, wptr
; FindFirstVolumeMountPointW lpszRootPathName, varptr(lpszVolumeMountPoint), cchBufferLength   ; 戻り値は stat
; lpszRootPathName : LPCWSTR -> "wptr"
; lpszVolumeMountPoint : LPWSTR out -> "wptr"
; cchBufferLength : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global FindFirstVolumeMountPointW "FindFirstVolumeMountPointW" wstr, var, int
; res = FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
; lpszRootPathName : LPCWSTR -> "wstr"
; lpszVolumeMountPoint : LPWSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE FindFirstVolumeMountPointW(LPCWSTR lpszRootPathName, LPWSTR lpszVolumeMountPoint, DWORD cchBufferLength)
#uselib "KERNEL32.dll"
#cfunc global FindFirstVolumeMountPointW "FindFirstVolumeMountPointW" wstr, var, int
; res = FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
; lpszRootPathName : LPCWSTR -> "wstr"
; lpszVolumeMountPoint : LPWSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindFirstVolumeMountPointW = kernel32.NewProc("FindFirstVolumeMountPointW")
)

// lpszRootPathName (LPCWSTR), lpszVolumeMountPoint (LPWSTR out), cchBufferLength (DWORD)
r1, _, err := procFindFirstVolumeMountPointW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszRootPathName))),
	uintptr(lpszVolumeMountPoint),
	uintptr(cchBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function FindFirstVolumeMountPointW(
  lpszRootPathName: PWideChar;   // LPCWSTR
  lpszVolumeMountPoint: PWideChar;   // LPWSTR out
  cchBufferLength: DWORD   // DWORD
): THandle; stdcall;
  external 'KERNEL32.dll' name 'FindFirstVolumeMountPointW';
result := DllCall("KERNEL32\FindFirstVolumeMountPointW"
    , "WStr", lpszRootPathName   ; LPCWSTR
    , "Ptr", lpszVolumeMountPoint   ; LPWSTR out
    , "UInt", cchBufferLength   ; DWORD
    , "Ptr")   ; return: HANDLE
●FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength) = DLL("KERNEL32.dll", "void* FindFirstVolumeMountPointW(char*, char*, dword)")
# 呼び出し: FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
# lpszRootPathName : LPCWSTR -> "char*"
# lpszVolumeMountPoint : LPWSTR out -> "char*"
# cchBufferLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn FindFirstVolumeMountPointW(
    lpszRootPathName: [*c]const u16, // LPCWSTR
    lpszVolumeMountPoint: [*c]u16, // LPWSTR out
    cchBufferLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc FindFirstVolumeMountPointW(
    lpszRootPathName: WideCString,  # LPCWSTR
    lpszVolumeMountPoint: ptr uint16,  # LPWSTR out
    cchBufferLength: uint32  # DWORD
): pointer {.importc: "FindFirstVolumeMountPointW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
void* FindFirstVolumeMountPointW(
    const(wchar)* lpszRootPathName,   // LPCWSTR
    wchar* lpszVolumeMountPoint,   // LPWSTR out
    uint cchBufferLength   // DWORD
);
ccall((:FindFirstVolumeMountPointW, "KERNEL32.dll"), stdcall, Ptr{Cvoid},
      (Cwstring, Ptr{UInt16}, UInt32),
      lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
# lpszRootPathName : LPCWSTR -> Cwstring
# lpszVolumeMountPoint : LPWSTR out -> Ptr{UInt16}
# cchBufferLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
void* FindFirstVolumeMountPointW(
    const uint16_t* lpszRootPathName,
    uint16_t* lpszVolumeMountPoint,
    uint32_t cchBufferLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
-- lpszRootPathName : LPCWSTR
-- lpszVolumeMountPoint : LPWSTR out
-- cchBufferLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const FindFirstVolumeMountPointW = lib.func('__stdcall', 'FindFirstVolumeMountPointW', 'void *', ['str16', 'uint16_t *', 'uint32_t']);
// FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
// lpszRootPathName : LPCWSTR -> 'str16'
// lpszVolumeMountPoint : LPWSTR out -> 'uint16_t *'
// cchBufferLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  FindFirstVolumeMountPointW: { parameters: ["buffer", "buffer", "u32"], result: "pointer" },
});
// lib.symbols.FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
// lpszRootPathName : LPCWSTR -> "buffer"
// lpszVolumeMountPoint : LPWSTR out -> "buffer"
// cchBufferLength : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* FindFirstVolumeMountPointW(
    const uint16_t* lpszRootPathName,
    uint16_t* lpszVolumeMountPoint,
    uint32_t cchBufferLength);
C, "KERNEL32.dll");
// $ffi->FindFirstVolumeMountPointW(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength);
// lpszRootPathName : LPCWSTR
// lpszVolumeMountPoint : LPWSTR out
// cchBufferLength : DWORD
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    Pointer FindFirstVolumeMountPointW(
        WString lpszRootPathName,   // LPCWSTR
        char[] lpszVolumeMountPoint,   // LPWSTR out
        int cchBufferLength   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun FindFirstVolumeMountPointW = FindFirstVolumeMountPointW(
    lpszRootPathName : UInt16*,   # LPCWSTR
    lpszVolumeMountPoint : UInt16*,   # LPWSTR out
    cchBufferLength : UInt32   # DWORD
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef FindFirstVolumeMountPointWNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef FindFirstVolumeMountPointWDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, int);
final FindFirstVolumeMountPointW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<FindFirstVolumeMountPointWNative, FindFirstVolumeMountPointWDart>('FindFirstVolumeMountPointW');
// lpszRootPathName : LPCWSTR -> Pointer<Utf16>
// lpszVolumeMountPoint : LPWSTR out -> Pointer<Utf16>
// cchBufferLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FindFirstVolumeMountPointW(
  lpszRootPathName: PWideChar;   // LPCWSTR
  lpszVolumeMountPoint: PWideChar;   // LPWSTR out
  cchBufferLength: DWORD   // DWORD
): THandle; stdcall;
  external 'KERNEL32.dll' name 'FindFirstVolumeMountPointW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "FindFirstVolumeMountPointW"
  c_FindFirstVolumeMountPointW :: CWString -> CWString -> Word32 -> IO (Ptr ())
-- lpszRootPathName : LPCWSTR -> CWString
-- lpszVolumeMountPoint : LPWSTR out -> CWString
-- cchBufferLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let findfirstvolumemountpointw =
  foreign "FindFirstVolumeMountPointW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning (ptr void))
(* lpszRootPathName : LPCWSTR -> (ptr uint16_t) *)
(* lpszVolumeMountPoint : LPWSTR out -> (ptr uint16_t) *)
(* cchBufferLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("FindFirstVolumeMountPointW" find-first-volume-mount-point-w :convention :stdcall) :pointer
  (lpsz-root-path-name (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-volume-mount-point :pointer)   ; LPWSTR out
  (cch-buffer-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FindFirstVolumeMountPointW = Win32::API::More->new('KERNEL32',
    'HANDLE FindFirstVolumeMountPointW(LPCWSTR lpszRootPathName, LPWSTR lpszVolumeMountPoint, DWORD cchBufferLength)');
# my $ret = $FindFirstVolumeMountPointW->Call($lpszRootPathName, $lpszVolumeMountPoint, $cchBufferLength);
# lpszRootPathName : LPCWSTR -> LPCWSTR
# lpszVolumeMountPoint : LPWSTR out -> LPWSTR
# cchBufferLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目