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

FindFirstVolumeMountPointW

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

シグネチャ

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

HANDLE FindFirstVolumeMountPointW(
    LPCWSTR lpszRootPathName,
    LPWSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);

パラメーター

名前方向
lpszRootPathNameLPCWSTRin
lpszVolumeMountPointLPWSTRout
cchBufferLengthDWORDin

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE FindFirstVolumeMountPointW(
    LPCWSTR lpszRootPathName,
    LPWSTR lpszVolumeMountPoint,
    DWORD cchBufferLength
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindFirstVolumeMountPointW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszRootPathName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumeMountPoint,   // LPWSTR out
    uint cchBufferLength   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindFirstVolumeMountPointW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszRootPathName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszVolumeMountPoint As System.Text.StringBuilder,   ' LPWSTR out
    cchBufferLength As UInteger   ' DWORD
) As IntPtr
End Function
' lpszRootPathName : LPCWSTR
' lpszVolumeMountPoint : LPWSTR out
' cchBufferLength : DWORD
Declare PtrSafe Function FindFirstVolumeMountPointW Lib "kernel32" ( _
    ByVal lpszRootPathName As LongPtr, _
    ByVal lpszVolumeMountPoint As LongPtr, _
    ByVal cchBufferLength As Long) As LongPtr
' 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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindFirstVolumeMountPointW = kernel32.NewProc("FindFirstVolumeMountPointW")
)

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