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

GetVolumePathNamesForVolumeNameA

関数
ボリューム名に対応するマウントパス一覧を取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL GetVolumePathNamesForVolumeNameA(
    LPCSTR lpszVolumeName,
    LPSTR lpszVolumePathNames,   // optional
    DWORD cchBufferLength,
    DWORD* lpcchReturnLength
);

パラメーター

名前方向説明
lpszVolumeNameLPCSTRinボリュームの GUID パス。ボリューム GUID パスは "\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" の形式です。
lpszVolumePathNamesLPSTRoutoptionalドライブ文字とマウントされたフォルダーパスの一覧を受け取るバッファーへのポインターです。この一覧は、追加の NULL 文字で終端される null 終端文字列の配列です。バッファーが一覧全体を保持するのに十分な大きさでない場合は、可能な限りの一覧がバッファーに格納されます。
cchBufferLengthDWORDinlpszVolumePathNames バッファーの長さ。すべての NULL 文字を含めた TCHAR 単位の長さです。
lpcchReturnLengthDWORD*out呼び出しが成功した場合、このパラメーターは lpszVolumePathNames バッファーにコピーされた TCHAR の数になります。それ以外の場合、このパラメーターは一覧全体を保持するために必要なバッファーのサイズ(TCHAR 単位)になります。

戻り値の型: BOOL

公式ドキュメント

指定したボリュームのドライブ文字とマウントされたフォルダーパスの一覧を取得します。(GetVolumePathNamesForVolumeNameA)

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。バッファーが一覧全体を保持するのに十分な大きさでない場合、エラーコードは ERROR_MORE_DATA になり、 lpcchReturnLength パラメーターには必要なバッファーサイズが格納されます。

解説(Remarks)

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

テクノロジー サポート
Server Message Block (SMB) 3.0 プロトコル 非対応
SMB 3.0 Transparent Failover (TFO) 非対応
SMB 3.0 with Scale-out File Shares (SO) 非対応
Cluster Shared Volume File System (CsvFS) 対応
Resilient File System (ReFS) 対応

SMB はボリューム管理関数をサポートしていません。

例については、 Displaying Volume Paths を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は 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>

BOOL GetVolumePathNamesForVolumeNameA(
    LPCSTR lpszVolumeName,
    LPSTR lpszVolumePathNames,   // optional
    DWORD cchBufferLength,
    DWORD* lpcchReturnLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetVolumePathNamesForVolumeNameA(
    [MarshalAs(UnmanagedType.LPStr)] string lpszVolumeName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszVolumePathNames,   // LPSTR optional, out
    uint cchBufferLength,   // DWORD
    out uint lpcchReturnLength   // DWORD* out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetVolumePathNamesForVolumeNameA(
    <MarshalAs(UnmanagedType.LPStr)> lpszVolumeName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpszVolumePathNames As System.Text.StringBuilder,   ' LPSTR optional, out
    cchBufferLength As UInteger,   ' DWORD
    <Out> ByRef lpcchReturnLength As UInteger   ' DWORD* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpszVolumeName : LPCSTR
' lpszVolumePathNames : LPSTR optional, out
' cchBufferLength : DWORD
' lpcchReturnLength : DWORD* out
Declare PtrSafe Function GetVolumePathNamesForVolumeNameA Lib "kernel32" ( _
    ByVal lpszVolumeName As String, _
    ByVal lpszVolumePathNames As String, _
    ByVal cchBufferLength As Long, _
    ByRef lpcchReturnLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetVolumePathNamesForVolumeNameA = ctypes.windll.kernel32.GetVolumePathNamesForVolumeNameA
GetVolumePathNamesForVolumeNameA.restype = wintypes.BOOL
GetVolumePathNamesForVolumeNameA.argtypes = [
    wintypes.LPCSTR,  # lpszVolumeName : LPCSTR
    wintypes.LPSTR,  # lpszVolumePathNames : LPSTR optional, out
    wintypes.DWORD,  # cchBufferLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpcchReturnLength : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetVolumePathNamesForVolumeNameA = Fiddle::Function.new(
  lib['GetVolumePathNamesForVolumeNameA'],
  [
    Fiddle::TYPE_VOIDP,  # lpszVolumeName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpszVolumePathNames : LPSTR optional, out
    -Fiddle::TYPE_INT,  # cchBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpcchReturnLength : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetVolumePathNamesForVolumeNameA(
        lpszVolumeName: *const u8,  // LPCSTR
        lpszVolumePathNames: *mut u8,  // LPSTR optional, out
        cchBufferLength: u32,  // DWORD
        lpcchReturnLength: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool GetVolumePathNamesForVolumeNameA([MarshalAs(UnmanagedType.LPStr)] string lpszVolumeName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszVolumePathNames, uint cchBufferLength, out uint lpcchReturnLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetVolumePathNamesForVolumeNameA' -Namespace Win32 -PassThru
# $api::GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
#uselib "KERNEL32.dll"
#func global GetVolumePathNamesForVolumeNameA "GetVolumePathNamesForVolumeNameA" sptr, sptr, sptr, sptr
; GetVolumePathNamesForVolumeNameA lpszVolumeName, varptr(lpszVolumePathNames), cchBufferLength, varptr(lpcchReturnLength)   ; 戻り値は stat
; lpszVolumeName : LPCSTR -> "sptr"
; lpszVolumePathNames : LPSTR optional, out -> "sptr"
; cchBufferLength : DWORD -> "sptr"
; lpcchReturnLength : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetVolumePathNamesForVolumeNameA "GetVolumePathNamesForVolumeNameA" str, var, int, var
; res = GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
; lpszVolumeName : LPCSTR -> "str"
; lpszVolumePathNames : LPSTR optional, out -> "var"
; cchBufferLength : DWORD -> "int"
; lpcchReturnLength : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetVolumePathNamesForVolumeNameA(LPCSTR lpszVolumeName, LPSTR lpszVolumePathNames, DWORD cchBufferLength, DWORD* lpcchReturnLength)
#uselib "KERNEL32.dll"
#cfunc global GetVolumePathNamesForVolumeNameA "GetVolumePathNamesForVolumeNameA" str, var, int, var
; res = GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
; lpszVolumeName : LPCSTR -> "str"
; lpszVolumePathNames : LPSTR optional, out -> "var"
; cchBufferLength : DWORD -> "int"
; lpcchReturnLength : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetVolumePathNamesForVolumeNameA = kernel32.NewProc("GetVolumePathNamesForVolumeNameA")
)

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

extern "kernel32" fn GetVolumePathNamesForVolumeNameA(
    lpszVolumeName: [*c]const u8, // LPCSTR
    lpszVolumePathNames: [*c]u8, // LPSTR optional, out
    cchBufferLength: u32, // DWORD
    lpcchReturnLength: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;
proc GetVolumePathNamesForVolumeNameA(
    lpszVolumeName: cstring,  # LPCSTR
    lpszVolumePathNames: ptr char,  # LPSTR optional, out
    cchBufferLength: uint32,  # DWORD
    lpcchReturnLength: ptr uint32  # DWORD* out
): int32 {.importc: "GetVolumePathNamesForVolumeNameA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int GetVolumePathNamesForVolumeNameA(
    const(char)* lpszVolumeName,   // LPCSTR
    char* lpszVolumePathNames,   // LPSTR optional, out
    uint cchBufferLength,   // DWORD
    uint* lpcchReturnLength   // DWORD* out
);
ccall((:GetVolumePathNamesForVolumeNameA, "KERNEL32.dll"), stdcall, Int32,
      (Cstring, Ptr{UInt8}, UInt32, Ptr{UInt32}),
      lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
# lpszVolumeName : LPCSTR -> Cstring
# lpszVolumePathNames : LPSTR optional, out -> Ptr{UInt8}
# cchBufferLength : DWORD -> UInt32
# lpcchReturnLength : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetVolumePathNamesForVolumeNameA(
    const char* lpszVolumeName,
    char* lpszVolumePathNames,
    uint32_t cchBufferLength,
    uint32_t* lpcchReturnLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
-- lpszVolumeName : LPCSTR
-- lpszVolumePathNames : LPSTR optional, out
-- cchBufferLength : DWORD
-- lpcchReturnLength : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetVolumePathNamesForVolumeNameA = lib.func('__stdcall', 'GetVolumePathNamesForVolumeNameA', 'int32_t', ['str', 'char *', 'uint32_t', 'uint32_t *']);
// GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
// lpszVolumeName : LPCSTR -> 'str'
// lpszVolumePathNames : LPSTR optional, out -> 'char *'
// cchBufferLength : DWORD -> 'uint32_t'
// lpcchReturnLength : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetVolumePathNamesForVolumeNameA: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
// lpszVolumeName : LPCSTR -> "buffer"
// lpszVolumePathNames : LPSTR optional, out -> "buffer"
// cchBufferLength : DWORD -> "u32"
// lpcchReturnLength : DWORD* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetVolumePathNamesForVolumeNameA(
    const char* lpszVolumeName,
    char* lpszVolumePathNames,
    uint32_t cchBufferLength,
    uint32_t* lpcchReturnLength);
C, "KERNEL32.dll");
// $ffi->GetVolumePathNamesForVolumeNameA(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength);
// lpszVolumeName : LPCSTR
// lpszVolumePathNames : LPSTR optional, out
// cchBufferLength : DWORD
// lpcchReturnLength : DWORD* out
// 構造体/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);
    boolean GetVolumePathNamesForVolumeNameA(
        String lpszVolumeName,   // LPCSTR
        byte[] lpszVolumePathNames,   // LPSTR optional, out
        int cchBufferLength,   // DWORD
        IntByReference lpcchReturnLength   // DWORD* out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun GetVolumePathNamesForVolumeNameA = GetVolumePathNamesForVolumeNameA(
    lpszVolumeName : UInt8*,   # LPCSTR
    lpszVolumePathNames : UInt8*,   # LPSTR optional, out
    cchBufferLength : UInt32,   # DWORD
    lpcchReturnLength : UInt32*   # DWORD* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetVolumePathNamesForVolumeNameANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef GetVolumePathNamesForVolumeNameADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Uint32>);
final GetVolumePathNamesForVolumeNameA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetVolumePathNamesForVolumeNameANative, GetVolumePathNamesForVolumeNameADart>('GetVolumePathNamesForVolumeNameA');
// lpszVolumeName : LPCSTR -> Pointer<Utf8>
// lpszVolumePathNames : LPSTR optional, out -> Pointer<Utf8>
// cchBufferLength : DWORD -> Uint32
// lpcchReturnLength : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetVolumePathNamesForVolumeNameA(
  lpszVolumeName: PAnsiChar;   // LPCSTR
  lpszVolumePathNames: PAnsiChar;   // LPSTR optional, out
  cchBufferLength: DWORD;   // DWORD
  lpcchReturnLength: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetVolumePathNamesForVolumeNameA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetVolumePathNamesForVolumeNameA"
  c_GetVolumePathNamesForVolumeNameA :: CString -> CString -> Word32 -> Ptr Word32 -> IO CInt
-- lpszVolumeName : LPCSTR -> CString
-- lpszVolumePathNames : LPSTR optional, out -> CString
-- cchBufferLength : DWORD -> Word32
-- lpcchReturnLength : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getvolumepathnamesforvolumenamea =
  foreign "GetVolumePathNamesForVolumeNameA"
    (string @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* lpszVolumeName : LPCSTR -> string *)
(* lpszVolumePathNames : LPSTR optional, out -> string *)
(* cchBufferLength : DWORD -> uint32_t *)
(* lpcchReturnLength : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetVolumePathNamesForVolumeNameA" get-volume-path-names-for-volume-name-a :convention :stdcall) :int32
  (lpsz-volume-name :string)   ; LPCSTR
  (lpsz-volume-path-names :pointer)   ; LPSTR optional, out
  (cch-buffer-length :uint32)   ; DWORD
  (lpcch-return-length :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetVolumePathNamesForVolumeNameA = Win32::API::More->new('KERNEL32',
    'BOOL GetVolumePathNamesForVolumeNameA(LPCSTR lpszVolumeName, LPSTR lpszVolumePathNames, DWORD cchBufferLength, LPVOID lpcchReturnLength)');
# my $ret = $GetVolumePathNamesForVolumeNameA->Call($lpszVolumeName, $lpszVolumePathNames, $cchBufferLength, $lpcchReturnLength);
# lpszVolumeName : LPCSTR -> LPCSTR
# lpszVolumePathNames : LPSTR optional, out -> LPSTR
# cchBufferLength : DWORD -> DWORD
# lpcchReturnLength : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い