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

GetVolumePathNamesForVolumeNameW

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

シグネチャ

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

BOOL GetVolumePathNamesForVolumeNameW(
    LPCWSTR lpszVolumeName,
    LPWSTR lpszVolumePathNames,   // optional
    DWORD cchBufferLength,
    DWORD* lpcchReturnLength
);

パラメーター

名前方向
lpszVolumeNameLPCWSTRin
lpszVolumePathNamesLPWSTRoutoptional
cchBufferLengthDWORDin
lpcchReturnLengthDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetVolumePathNamesForVolumeNameW(
    LPCWSTR lpszVolumeName,
    LPWSTR lpszVolumePathNames,   // optional
    DWORD cchBufferLength,
    DWORD* lpcchReturnLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetVolumePathNamesForVolumeNameW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszVolumeName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumePathNames,   // LPWSTR optional, out
    uint cchBufferLength,   // DWORD
    out uint lpcchReturnLength   // DWORD* out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetVolumePathNamesForVolumeNameW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumeName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumePathNames As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchBufferLength As UInteger,   ' DWORD
    <Out> ByRef lpcchReturnLength As UInteger   ' DWORD* out
) As Boolean
End Function
' lpszVolumeName : LPCWSTR
' lpszVolumePathNames : LPWSTR optional, out
' cchBufferLength : DWORD
' lpcchReturnLength : DWORD* out
Declare PtrSafe Function GetVolumePathNamesForVolumeNameW Lib "kernel32" ( _
    ByVal lpszVolumeName As LongPtr, _
    ByVal lpszVolumePathNames As LongPtr, _
    ByVal cchBufferLength As Long, _
    ByRef lpcchReturnLength As Long) As Long
' 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

GetVolumePathNamesForVolumeNameW = ctypes.windll.kernel32.GetVolumePathNamesForVolumeNameW
GetVolumePathNamesForVolumeNameW.restype = wintypes.BOOL
GetVolumePathNamesForVolumeNameW.argtypes = [
    wintypes.LPCWSTR,  # lpszVolumeName : LPCWSTR
    wintypes.LPWSTR,  # lpszVolumePathNames : LPWSTR 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')
GetVolumePathNamesForVolumeNameW = Fiddle::Function.new(
  lib['GetVolumePathNamesForVolumeNameW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszVolumeName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpszVolumePathNames : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # cchBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpcchReturnLength : DWORD* out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetVolumePathNamesForVolumeNameW(
        lpszVolumeName: *const u16,  // LPCWSTR
        lpszVolumePathNames: *mut u16,  // LPWSTR 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.Unicode, SetLastError = true)]
public static extern bool GetVolumePathNamesForVolumeNameW([MarshalAs(UnmanagedType.LPWStr)] string lpszVolumeName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumePathNames, uint cchBufferLength, out uint lpcchReturnLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetVolumePathNamesForVolumeNameW' -Namespace Win32 -PassThru
# $api::GetVolumePathNamesForVolumeNameW(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
#uselib "KERNEL32.dll"
#func global GetVolumePathNamesForVolumeNameW "GetVolumePathNamesForVolumeNameW" wptr, wptr, wptr, wptr
; GetVolumePathNamesForVolumeNameW lpszVolumeName, varptr(lpszVolumePathNames), cchBufferLength, varptr(lpcchReturnLength)   ; 戻り値は stat
; lpszVolumeName : LPCWSTR -> "wptr"
; lpszVolumePathNames : LPWSTR optional, out -> "wptr"
; cchBufferLength : DWORD -> "wptr"
; lpcchReturnLength : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetVolumePathNamesForVolumeNameW "GetVolumePathNamesForVolumeNameW" wstr, var, int, var
; res = GetVolumePathNamesForVolumeNameW(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
; lpszVolumeName : LPCWSTR -> "wstr"
; lpszVolumePathNames : LPWSTR optional, out -> "var"
; cchBufferLength : DWORD -> "int"
; lpcchReturnLength : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetVolumePathNamesForVolumeNameW(LPCWSTR lpszVolumeName, LPWSTR lpszVolumePathNames, DWORD cchBufferLength, DWORD* lpcchReturnLength)
#uselib "KERNEL32.dll"
#cfunc global GetVolumePathNamesForVolumeNameW "GetVolumePathNamesForVolumeNameW" wstr, var, int, var
; res = GetVolumePathNamesForVolumeNameW(lpszVolumeName, lpszVolumePathNames, cchBufferLength, lpcchReturnLength)
; lpszVolumeName : LPCWSTR -> "wstr"
; lpszVolumePathNames : LPWSTR 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")
	procGetVolumePathNamesForVolumeNameW = kernel32.NewProc("GetVolumePathNamesForVolumeNameW")
)

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