Win32 API 日本語リファレンス
ホームNetworking.Clustering › ClusterGetVolumePathName

ClusterGetVolumePathName

関数
ファイルパスからボリュームのマウントパスを取得する。
DLLRESUTILS.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

// RESUTILS.dll
#include <windows.h>

BOOL ClusterGetVolumePathName(
    LPCWSTR lpszFileName,
    LPWSTR lpszVolumePathName,
    DWORD cchBufferLength
);

パラメーター

名前方向説明
lpszFileNameLPCWSTRin対象ファイルまたはディレクトリのパス。
lpszVolumePathNameLPWSTRout取得したボリュームマウントポイントパスを受け取るバッファー。
cchBufferLengthDWORDinlpszVolumePathNameバッファーの文字数。

戻り値の型: BOOL

各言語での呼び出し定義

// RESUTILS.dll
#include <windows.h>

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

ClusterGetVolumePathName = ctypes.windll.resutils.ClusterGetVolumePathName
ClusterGetVolumePathName.restype = wintypes.BOOL
ClusterGetVolumePathName.argtypes = [
    wintypes.LPCWSTR,  # lpszFileName : LPCWSTR
    wintypes.LPWSTR,  # lpszVolumePathName : 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('RESUTILS.dll')
ClusterGetVolumePathName = Fiddle::Function.new(
  lib['ClusterGetVolumePathName'],
  [
    Fiddle::TYPE_VOIDP,  # lpszFileName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpszVolumePathName : LPWSTR out
    -Fiddle::TYPE_INT,  # cchBufferLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "resutils")]
extern "system" {
    fn ClusterGetVolumePathName(
        lpszFileName: *const u16,  // LPCWSTR
        lpszVolumePathName: *mut u16,  // LPWSTR out
        cchBufferLength: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("RESUTILS.dll", SetLastError = true)]
public static extern bool ClusterGetVolumePathName([MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszVolumePathName, uint cchBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RESUTILS_ClusterGetVolumePathName' -Namespace Win32 -PassThru
# $api::ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
#uselib "RESUTILS.dll"
#func global ClusterGetVolumePathName "ClusterGetVolumePathName" sptr, sptr, sptr
; ClusterGetVolumePathName lpszFileName, varptr(lpszVolumePathName), cchBufferLength   ; 戻り値は stat
; lpszFileName : LPCWSTR -> "sptr"
; lpszVolumePathName : LPWSTR out -> "sptr"
; cchBufferLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "RESUTILS.dll"
#cfunc global ClusterGetVolumePathName "ClusterGetVolumePathName" wstr, var, int
; res = ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
; lpszFileName : LPCWSTR -> "wstr"
; lpszVolumePathName : LPWSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ClusterGetVolumePathName(LPCWSTR lpszFileName, LPWSTR lpszVolumePathName, DWORD cchBufferLength)
#uselib "RESUTILS.dll"
#cfunc global ClusterGetVolumePathName "ClusterGetVolumePathName" wstr, var, int
; res = ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
; lpszFileName : LPCWSTR -> "wstr"
; lpszVolumePathName : LPWSTR out -> "var"
; cchBufferLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	resutils = windows.NewLazySystemDLL("RESUTILS.dll")
	procClusterGetVolumePathName = resutils.NewProc("ClusterGetVolumePathName")
)

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

extern "resutils" fn ClusterGetVolumePathName(
    lpszFileName: [*c]const u16, // LPCWSTR
    lpszVolumePathName: [*c]u16, // LPWSTR out
    cchBufferLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc ClusterGetVolumePathName(
    lpszFileName: WideCString,  # LPCWSTR
    lpszVolumePathName: ptr uint16,  # LPWSTR out
    cchBufferLength: uint32  # DWORD
): int32 {.importc: "ClusterGetVolumePathName", stdcall, dynlib: "RESUTILS.dll".}
pragma(lib, "resutils");
extern(Windows)
int ClusterGetVolumePathName(
    const(wchar)* lpszFileName,   // LPCWSTR
    wchar* lpszVolumePathName,   // LPWSTR out
    uint cchBufferLength   // DWORD
);
ccall((:ClusterGetVolumePathName, "RESUTILS.dll"), stdcall, Int32,
      (Cwstring, Ptr{UInt16}, UInt32),
      lpszFileName, lpszVolumePathName, cchBufferLength)
# lpszFileName : LPCWSTR -> Cwstring
# lpszVolumePathName : LPWSTR out -> Ptr{UInt16}
# cchBufferLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ClusterGetVolumePathName(
    const uint16_t* lpszFileName,
    uint16_t* lpszVolumePathName,
    uint32_t cchBufferLength);
]]
local resutils = ffi.load("resutils")
-- resutils.ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
-- lpszFileName : LPCWSTR
-- lpszVolumePathName : LPWSTR out
-- cchBufferLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('RESUTILS.dll');
const ClusterGetVolumePathName = lib.func('__stdcall', 'ClusterGetVolumePathName', 'int32_t', ['str16', 'uint16_t *', 'uint32_t']);
// ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
// lpszFileName : LPCWSTR -> 'str16'
// lpszVolumePathName : LPWSTR out -> 'uint16_t *'
// cchBufferLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("RESUTILS.dll", {
  ClusterGetVolumePathName: { parameters: ["buffer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength)
// lpszFileName : LPCWSTR -> "buffer"
// lpszVolumePathName : LPWSTR out -> "buffer"
// cchBufferLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ClusterGetVolumePathName(
    const uint16_t* lpszFileName,
    uint16_t* lpszVolumePathName,
    uint32_t cchBufferLength);
C, "RESUTILS.dll");
// $ffi->ClusterGetVolumePathName(lpszFileName, lpszVolumePathName, cchBufferLength);
// lpszFileName : LPCWSTR
// lpszVolumePathName : LPWSTR out
// cchBufferLength : DWORD
// 構造体/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 Resutils extends StdCallLibrary {
    Resutils INSTANCE = Native.load("resutils", Resutils.class);
    boolean ClusterGetVolumePathName(
        WString lpszFileName,   // LPCWSTR
        char[] lpszVolumePathName,   // LPWSTR out
        int cchBufferLength   // DWORD
    );
}
@[Link("resutils")]
lib LibRESUTILS
  fun ClusterGetVolumePathName = ClusterGetVolumePathName(
    lpszFileName : UInt16*,   # LPCWSTR
    lpszVolumePathName : UInt16*,   # LPWSTR out
    cchBufferLength : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ClusterGetVolumePathNameNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef ClusterGetVolumePathNameDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final ClusterGetVolumePathName = DynamicLibrary.open('RESUTILS.dll')
    .lookupFunction<ClusterGetVolumePathNameNative, ClusterGetVolumePathNameDart>('ClusterGetVolumePathName');
// lpszFileName : LPCWSTR -> Pointer<Utf16>
// lpszVolumePathName : LPWSTR out -> Pointer<Utf16>
// cchBufferLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterGetVolumePathName(
  lpszFileName: PWideChar;   // LPCWSTR
  lpszVolumePathName: PWideChar;   // LPWSTR out
  cchBufferLength: DWORD   // DWORD
): BOOL; stdcall;
  external 'RESUTILS.dll' name 'ClusterGetVolumePathName';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ClusterGetVolumePathName"
  c_ClusterGetVolumePathName :: CWString -> CWString -> Word32 -> IO CInt
-- lpszFileName : LPCWSTR -> CWString
-- lpszVolumePathName : LPWSTR out -> CWString
-- cchBufferLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let clustergetvolumepathname =
  foreign "ClusterGetVolumePathName"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* lpszFileName : LPCWSTR -> (ptr uint16_t) *)
(* lpszVolumePathName : LPWSTR out -> (ptr uint16_t) *)
(* cchBufferLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library resutils (t "RESUTILS.dll"))
(cffi:use-foreign-library resutils)

(cffi:defcfun ("ClusterGetVolumePathName" cluster-get-volume-path-name :convention :stdcall) :int32
  (lpsz-file-name (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-volume-path-name :pointer)   ; LPWSTR out
  (cch-buffer-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterGetVolumePathName = Win32::API::More->new('RESUTILS',
    'BOOL ClusterGetVolumePathName(LPCWSTR lpszFileName, LPWSTR lpszVolumePathName, DWORD cchBufferLength)');
# my $ret = $ClusterGetVolumePathName->Call($lpszFileName, $lpszVolumePathName, $cchBufferLength);
# lpszFileName : LPCWSTR -> LPCWSTR
# lpszVolumePathName : LPWSTR out -> LPWSTR
# cchBufferLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。