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

FindFirstVolumeMountPointA

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

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HANDLE FindFirstVolumeMountPointA(
    LPCSTR lpszRootPathName,
    LPSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);

パラメーター

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

戻り値の型: HANDLE

公式ドキュメント

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

戻り値

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

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

解説(Remarks)

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

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

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

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 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーやランタイムエラーを引き起こす不一致が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

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

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HANDLE FindFirstVolumeMountPointA(
    LPCSTR lpszRootPathName,
    LPSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindFirstVolumeMountPointA(
    [MarshalAs(UnmanagedType.LPStr)] string lpszRootPathName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszVolumeMountPoint,   // LPSTR out
    uint cchBufferLength   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindFirstVolumeMountPointA(
    <MarshalAs(UnmanagedType.LPStr)> lpszRootPathName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpszVolumeMountPoint As System.Text.StringBuilder,   ' LPSTR out
    cchBufferLength As UInteger   ' DWORD
) As IntPtr
End Function
' lpszRootPathName : LPCSTR
' lpszVolumeMountPoint : LPSTR out
' cchBufferLength : DWORD
Declare PtrSafe Function FindFirstVolumeMountPointA Lib "kernel32" ( _
    ByVal lpszRootPathName As String, _
    ByVal lpszVolumeMountPoint As String, _
    ByVal cchBufferLength As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindFirstVolumeMountPointA = ctypes.windll.kernel32.FindFirstVolumeMountPointA
FindFirstVolumeMountPointA.restype = ctypes.c_void_p
FindFirstVolumeMountPointA.argtypes = [
    wintypes.LPCSTR,  # lpszRootPathName : LPCSTR
    wintypes.LPSTR,  # lpszVolumeMountPoint : LPSTR 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')
FindFirstVolumeMountPointA = Fiddle::Function.new(
  lib['FindFirstVolumeMountPointA'],
  [
    Fiddle::TYPE_VOIDP,  # lpszRootPathName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpszVolumeMountPoint : LPSTR out
    -Fiddle::TYPE_INT,  # cchBufferLength : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn FindFirstVolumeMountPointA(
        lpszRootPathName: *const u8,  // LPCSTR
        lpszVolumeMountPoint: *mut u8,  // LPSTR 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.Ansi, SetLastError = true)]
public static extern IntPtr FindFirstVolumeMountPointA([MarshalAs(UnmanagedType.LPStr)] string lpszRootPathName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszVolumeMountPoint, uint cchBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindFirstVolumeMountPointA' -Namespace Win32 -PassThru
# $api::FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
#uselib "KERNEL32.dll"
#func global FindFirstVolumeMountPointA "FindFirstVolumeMountPointA" sptr, sptr, sptr
; FindFirstVolumeMountPointA lpszRootPathName, varptr(lpszVolumeMountPoint), cchBufferLength   ; 戻り値は stat
; lpszRootPathName : LPCSTR -> "sptr"
; lpszVolumeMountPoint : LPSTR out -> "sptr"
; cchBufferLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global FindFirstVolumeMountPointA "FindFirstVolumeMountPointA" str, var, int
; res = FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
; lpszRootPathName : LPCSTR -> "str"
; lpszVolumeMountPoint : LPSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE FindFirstVolumeMountPointA(LPCSTR lpszRootPathName, LPSTR lpszVolumeMountPoint, DWORD cchBufferLength)
#uselib "KERNEL32.dll"
#cfunc global FindFirstVolumeMountPointA "FindFirstVolumeMountPointA" str, var, int
; res = FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
; lpszRootPathName : LPCSTR -> "str"
; lpszVolumeMountPoint : LPSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindFirstVolumeMountPointA = kernel32.NewProc("FindFirstVolumeMountPointA")
)

// lpszRootPathName (LPCSTR), lpszVolumeMountPoint (LPSTR out), cchBufferLength (DWORD)
r1, _, err := procFindFirstVolumeMountPointA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszRootPathName))),
	uintptr(lpszVolumeMountPoint),
	uintptr(cchBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function FindFirstVolumeMountPointA(
  lpszRootPathName: PAnsiChar;   // LPCSTR
  lpszVolumeMountPoint: PAnsiChar;   // LPSTR out
  cchBufferLength: DWORD   // DWORD
): THandle; stdcall;
  external 'KERNEL32.dll' name 'FindFirstVolumeMountPointA';
result := DllCall("KERNEL32\FindFirstVolumeMountPointA"
    , "AStr", lpszRootPathName   ; LPCSTR
    , "Ptr", lpszVolumeMountPoint   ; LPSTR out
    , "UInt", cchBufferLength   ; DWORD
    , "Ptr")   ; return: HANDLE
●FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength) = DLL("KERNEL32.dll", "void* FindFirstVolumeMountPointA(char*, char*, dword)")
# 呼び出し: FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
# lpszRootPathName : LPCSTR -> "char*"
# lpszVolumeMountPoint : LPSTR out -> "char*"
# cchBufferLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn FindFirstVolumeMountPointA(
    lpszRootPathName: [*c]const u8, // LPCSTR
    lpszVolumeMountPoint: [*c]u8, // LPSTR out
    cchBufferLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc FindFirstVolumeMountPointA(
    lpszRootPathName: cstring,  # LPCSTR
    lpszVolumeMountPoint: ptr char,  # LPSTR out
    cchBufferLength: uint32  # DWORD
): pointer {.importc: "FindFirstVolumeMountPointA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
void* FindFirstVolumeMountPointA(
    const(char)* lpszRootPathName,   // LPCSTR
    char* lpszVolumeMountPoint,   // LPSTR out
    uint cchBufferLength   // DWORD
);
ccall((:FindFirstVolumeMountPointA, "KERNEL32.dll"), stdcall, Ptr{Cvoid},
      (Cstring, Ptr{UInt8}, UInt32),
      lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
# lpszRootPathName : LPCSTR -> Cstring
# lpszVolumeMountPoint : LPSTR out -> Ptr{UInt8}
# cchBufferLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* FindFirstVolumeMountPointA(
    const char* lpszRootPathName,
    char* lpszVolumeMountPoint,
    uint32_t cchBufferLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
-- lpszRootPathName : LPCSTR
-- lpszVolumeMountPoint : LPSTR out
-- cchBufferLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const FindFirstVolumeMountPointA = lib.func('__stdcall', 'FindFirstVolumeMountPointA', 'void *', ['str', 'char *', 'uint32_t']);
// FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
// lpszRootPathName : LPCSTR -> 'str'
// lpszVolumeMountPoint : LPSTR out -> 'char *'
// cchBufferLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  FindFirstVolumeMountPointA: { parameters: ["buffer", "buffer", "u32"], result: "pointer" },
});
// lib.symbols.FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength)
// lpszRootPathName : LPCSTR -> "buffer"
// lpszVolumeMountPoint : LPSTR out -> "buffer"
// cchBufferLength : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* FindFirstVolumeMountPointA(
    const char* lpszRootPathName,
    char* lpszVolumeMountPoint,
    uint32_t cchBufferLength);
C, "KERNEL32.dll");
// $ffi->FindFirstVolumeMountPointA(lpszRootPathName, lpszVolumeMountPoint, cchBufferLength);
// lpszRootPathName : LPCSTR
// lpszVolumeMountPoint : LPSTR 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.ASCII_OPTIONS);
    Pointer FindFirstVolumeMountPointA(
        String lpszRootPathName,   // LPCSTR
        byte[] lpszVolumeMountPoint,   // LPSTR out
        int cchBufferLength   // DWORD
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun FindFirstVolumeMountPointA = FindFirstVolumeMountPointA(
    lpszRootPathName : UInt8*,   # LPCSTR
    lpszVolumeMountPoint : UInt8*,   # LPSTR 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 FindFirstVolumeMountPointANative = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Uint32);
typedef FindFirstVolumeMountPointADart = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, int);
final FindFirstVolumeMountPointA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<FindFirstVolumeMountPointANative, FindFirstVolumeMountPointADart>('FindFirstVolumeMountPointA');
// lpszRootPathName : LPCSTR -> Pointer<Utf8>
// lpszVolumeMountPoint : LPSTR out -> Pointer<Utf8>
// cchBufferLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FindFirstVolumeMountPointA(
  lpszRootPathName: PAnsiChar;   // LPCSTR
  lpszVolumeMountPoint: PAnsiChar;   // LPSTR out
  cchBufferLength: DWORD   // DWORD
): THandle; stdcall;
  external 'KERNEL32.dll' name 'FindFirstVolumeMountPointA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let findfirstvolumemountpointa =
  foreign "FindFirstVolumeMountPointA"
    (string @-> string @-> uint32_t @-> returning (ptr void))
(* lpszRootPathName : LPCSTR -> string *)
(* lpszVolumeMountPoint : LPSTR out -> string *)
(* 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 ("FindFirstVolumeMountPointA" find-first-volume-mount-point-a :convention :stdcall) :pointer
  (lpsz-root-path-name :string)   ; LPCSTR
  (lpsz-volume-mount-point :pointer)   ; LPSTR out
  (cch-buffer-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FindFirstVolumeMountPointA = Win32::API::More->new('KERNEL32',
    'HANDLE FindFirstVolumeMountPointA(LPCSTR lpszRootPathName, LPSTR lpszVolumeMountPoint, DWORD cchBufferLength)');
# my $ret = $FindFirstVolumeMountPointA->Call($lpszRootPathName, $lpszVolumeMountPoint, $cchBufferLength);
# lpszRootPathName : LPCSTR -> LPCSTR
# lpszVolumeMountPoint : LPSTR out -> LPSTR
# cchBufferLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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