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
lpszVolumePathNamesLPSTRoutoptional
cchBufferLengthDWORDin
lpcchReturnLengthDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

// 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 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)。