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

GetVolumePathNameA

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

シグネチャ

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

BOOL GetVolumePathNameA(
    LPCSTR lpszFileName,
    LPSTR lpszVolumePathName,
    DWORD cchBufferLength
);

パラメーター

名前方向
lpszFileNameLPCSTRin
lpszVolumePathNameLPSTRout
cchBufferLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetVolumePathNameA = kernel32.NewProc("GetVolumePathNameA")
)

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