ホーム › Storage.Vhd › GetAllAttachedVirtualDiskPhysicalPaths
GetAllAttachedVirtualDiskPhysicalPaths
関数接続中の全仮想ディスクの物理パス一覧を取得する。
シグネチャ
// VirtDisk.dll
#include <windows.h>
WIN32_ERROR GetAllAttachedVirtualDiskPhysicalPaths(
DWORD* PathsBufferSizeInBytes,
LPWSTR PathsBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PathsBufferSizeInBytes | DWORD* | inout | 入力でPathsBufferのバイトサイズ、出力で必要サイズを受け取る入出力ポインタ。 |
| PathsBuffer | LPWSTR | out | アタッチ済み全仮想ディスクの物理パスをマルチ文字列で受け取る出力バッファ。NULLでサイズ照会可。 |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// VirtDisk.dll
#include <windows.h>
WIN32_ERROR GetAllAttachedVirtualDiskPhysicalPaths(
DWORD* PathsBufferSizeInBytes,
LPWSTR PathsBuffer
);[DllImport("VirtDisk.dll", ExactSpelling = true)]
static extern uint GetAllAttachedVirtualDiskPhysicalPaths(
ref uint PathsBufferSizeInBytes, // DWORD* in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathsBuffer // LPWSTR out
);<DllImport("VirtDisk.dll", ExactSpelling:=True)>
Public Shared Function GetAllAttachedVirtualDiskPhysicalPaths(
ByRef PathsBufferSizeInBytes As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPWStr)> PathsBuffer As System.Text.StringBuilder ' LPWSTR out
) As UInteger
End Function' PathsBufferSizeInBytes : DWORD* in/out
' PathsBuffer : LPWSTR out
Declare PtrSafe Function GetAllAttachedVirtualDiskPhysicalPaths Lib "virtdisk" ( _
ByRef PathsBufferSizeInBytes As Long, _
ByVal PathsBuffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetAllAttachedVirtualDiskPhysicalPaths = ctypes.windll.virtdisk.GetAllAttachedVirtualDiskPhysicalPaths
GetAllAttachedVirtualDiskPhysicalPaths.restype = wintypes.DWORD
GetAllAttachedVirtualDiskPhysicalPaths.argtypes = [
ctypes.POINTER(wintypes.DWORD), # PathsBufferSizeInBytes : DWORD* in/out
wintypes.LPWSTR, # PathsBuffer : LPWSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('VirtDisk.dll')
GetAllAttachedVirtualDiskPhysicalPaths = Fiddle::Function.new(
lib['GetAllAttachedVirtualDiskPhysicalPaths'],
[
Fiddle::TYPE_VOIDP, # PathsBufferSizeInBytes : DWORD* in/out
Fiddle::TYPE_VOIDP, # PathsBuffer : LPWSTR out
],
-Fiddle::TYPE_INT)#[link(name = "virtdisk")]
extern "system" {
fn GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes: *mut u32, // DWORD* in/out
PathsBuffer: *mut u16 // LPWSTR out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("VirtDisk.dll")]
public static extern uint GetAllAttachedVirtualDiskPhysicalPaths(ref uint PathsBufferSizeInBytes, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathsBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'VirtDisk_GetAllAttachedVirtualDiskPhysicalPaths' -Namespace Win32 -PassThru
# $api::GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer)#uselib "VirtDisk.dll"
#func global GetAllAttachedVirtualDiskPhysicalPaths "GetAllAttachedVirtualDiskPhysicalPaths" sptr, sptr
; GetAllAttachedVirtualDiskPhysicalPaths varptr(PathsBufferSizeInBytes), varptr(PathsBuffer) ; 戻り値は stat
; PathsBufferSizeInBytes : DWORD* in/out -> "sptr"
; PathsBuffer : LPWSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "VirtDisk.dll" #cfunc global GetAllAttachedVirtualDiskPhysicalPaths "GetAllAttachedVirtualDiskPhysicalPaths" var, var ; res = GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer) ; PathsBufferSizeInBytes : DWORD* in/out -> "var" ; PathsBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "VirtDisk.dll" #cfunc global GetAllAttachedVirtualDiskPhysicalPaths "GetAllAttachedVirtualDiskPhysicalPaths" sptr, sptr ; res = GetAllAttachedVirtualDiskPhysicalPaths(varptr(PathsBufferSizeInBytes), varptr(PathsBuffer)) ; PathsBufferSizeInBytes : DWORD* in/out -> "sptr" ; PathsBuffer : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR GetAllAttachedVirtualDiskPhysicalPaths(DWORD* PathsBufferSizeInBytes, LPWSTR PathsBuffer) #uselib "VirtDisk.dll" #cfunc global GetAllAttachedVirtualDiskPhysicalPaths "GetAllAttachedVirtualDiskPhysicalPaths" var, var ; res = GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer) ; PathsBufferSizeInBytes : DWORD* in/out -> "var" ; PathsBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR GetAllAttachedVirtualDiskPhysicalPaths(DWORD* PathsBufferSizeInBytes, LPWSTR PathsBuffer) #uselib "VirtDisk.dll" #cfunc global GetAllAttachedVirtualDiskPhysicalPaths "GetAllAttachedVirtualDiskPhysicalPaths" intptr, intptr ; res = GetAllAttachedVirtualDiskPhysicalPaths(varptr(PathsBufferSizeInBytes), varptr(PathsBuffer)) ; PathsBufferSizeInBytes : DWORD* in/out -> "intptr" ; PathsBuffer : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
virtdisk = windows.NewLazySystemDLL("VirtDisk.dll")
procGetAllAttachedVirtualDiskPhysicalPaths = virtdisk.NewProc("GetAllAttachedVirtualDiskPhysicalPaths")
)
// PathsBufferSizeInBytes (DWORD* in/out), PathsBuffer (LPWSTR out)
r1, _, err := procGetAllAttachedVirtualDiskPhysicalPaths.Call(
uintptr(PathsBufferSizeInBytes),
uintptr(PathsBuffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes: Pointer; // DWORD* in/out
PathsBuffer: PWideChar // LPWSTR out
): DWORD; stdcall;
external 'VirtDisk.dll' name 'GetAllAttachedVirtualDiskPhysicalPaths';result := DllCall("VirtDisk\GetAllAttachedVirtualDiskPhysicalPaths"
, "Ptr", PathsBufferSizeInBytes ; DWORD* in/out
, "Ptr", PathsBuffer ; LPWSTR out
, "UInt") ; return: WIN32_ERROR●GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer) = DLL("VirtDisk.dll", "dword GetAllAttachedVirtualDiskPhysicalPaths(void*, char*)")
# 呼び出し: GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer)
# PathsBufferSizeInBytes : DWORD* in/out -> "void*"
# PathsBuffer : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "virtdisk" fn GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes: [*c]u32, // DWORD* in/out
PathsBuffer: [*c]u16 // LPWSTR out
) callconv(std.os.windows.WINAPI) u32;proc GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes: ptr uint32, # DWORD* in/out
PathsBuffer: ptr uint16 # LPWSTR out
): uint32 {.importc: "GetAllAttachedVirtualDiskPhysicalPaths", stdcall, dynlib: "VirtDisk.dll".}pragma(lib, "virtdisk");
extern(Windows)
uint GetAllAttachedVirtualDiskPhysicalPaths(
uint* PathsBufferSizeInBytes, // DWORD* in/out
wchar* PathsBuffer // LPWSTR out
);ccall((:GetAllAttachedVirtualDiskPhysicalPaths, "VirtDisk.dll"), stdcall, UInt32,
(Ptr{UInt32}, Ptr{UInt16}),
PathsBufferSizeInBytes, PathsBuffer)
# PathsBufferSizeInBytes : DWORD* in/out -> Ptr{UInt32}
# PathsBuffer : LPWSTR out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetAllAttachedVirtualDiskPhysicalPaths(
uint32_t* PathsBufferSizeInBytes,
uint16_t* PathsBuffer);
]]
local virtdisk = ffi.load("virtdisk")
-- virtdisk.GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer)
-- PathsBufferSizeInBytes : DWORD* in/out
-- PathsBuffer : LPWSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('VirtDisk.dll');
const GetAllAttachedVirtualDiskPhysicalPaths = lib.func('__stdcall', 'GetAllAttachedVirtualDiskPhysicalPaths', 'uint32_t', ['uint32_t *', 'uint16_t *']);
// GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer)
// PathsBufferSizeInBytes : DWORD* in/out -> 'uint32_t *'
// PathsBuffer : LPWSTR out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("VirtDisk.dll", {
GetAllAttachedVirtualDiskPhysicalPaths: { parameters: ["pointer", "buffer"], result: "u32" },
});
// lib.symbols.GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer)
// PathsBufferSizeInBytes : DWORD* in/out -> "pointer"
// PathsBuffer : LPWSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetAllAttachedVirtualDiskPhysicalPaths(
uint32_t* PathsBufferSizeInBytes,
uint16_t* PathsBuffer);
C, "VirtDisk.dll");
// $ffi->GetAllAttachedVirtualDiskPhysicalPaths(PathsBufferSizeInBytes, PathsBuffer);
// PathsBufferSizeInBytes : DWORD* in/out
// PathsBuffer : LPWSTR out
// 構造体/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 Virtdisk extends StdCallLibrary {
Virtdisk INSTANCE = Native.load("virtdisk", Virtdisk.class);
int GetAllAttachedVirtualDiskPhysicalPaths(
IntByReference PathsBufferSizeInBytes, // DWORD* in/out
char[] PathsBuffer // LPWSTR out
);
}@[Link("virtdisk")]
lib LibVirtDisk
fun GetAllAttachedVirtualDiskPhysicalPaths = GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes : UInt32*, # DWORD* in/out
PathsBuffer : UInt16* # LPWSTR out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetAllAttachedVirtualDiskPhysicalPathsNative = Uint32 Function(Pointer<Uint32>, Pointer<Utf16>);
typedef GetAllAttachedVirtualDiskPhysicalPathsDart = int Function(Pointer<Uint32>, Pointer<Utf16>);
final GetAllAttachedVirtualDiskPhysicalPaths = DynamicLibrary.open('VirtDisk.dll')
.lookupFunction<GetAllAttachedVirtualDiskPhysicalPathsNative, GetAllAttachedVirtualDiskPhysicalPathsDart>('GetAllAttachedVirtualDiskPhysicalPaths');
// PathsBufferSizeInBytes : DWORD* in/out -> Pointer<Uint32>
// PathsBuffer : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetAllAttachedVirtualDiskPhysicalPaths(
PathsBufferSizeInBytes: Pointer; // DWORD* in/out
PathsBuffer: PWideChar // LPWSTR out
): DWORD; stdcall;
external 'VirtDisk.dll' name 'GetAllAttachedVirtualDiskPhysicalPaths';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetAllAttachedVirtualDiskPhysicalPaths"
c_GetAllAttachedVirtualDiskPhysicalPaths :: Ptr Word32 -> CWString -> IO Word32
-- PathsBufferSizeInBytes : DWORD* in/out -> Ptr Word32
-- PathsBuffer : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getallattachedvirtualdiskphysicalpaths =
foreign "GetAllAttachedVirtualDiskPhysicalPaths"
((ptr uint32_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* PathsBufferSizeInBytes : DWORD* in/out -> (ptr uint32_t) *)
(* PathsBuffer : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library virtdisk (t "VirtDisk.dll"))
(cffi:use-foreign-library virtdisk)
(cffi:defcfun ("GetAllAttachedVirtualDiskPhysicalPaths" get-all-attached-virtual-disk-physical-paths :convention :stdcall) :uint32
(paths-buffer-size-in-bytes :pointer) ; DWORD* in/out
(paths-buffer :pointer)) ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetAllAttachedVirtualDiskPhysicalPaths = Win32::API::More->new('VirtDisk',
'DWORD GetAllAttachedVirtualDiskPhysicalPaths(LPVOID PathsBufferSizeInBytes, LPWSTR PathsBuffer)');
# my $ret = $GetAllAttachedVirtualDiskPhysicalPaths->Call($PathsBufferSizeInBytes, $PathsBuffer);
# PathsBufferSizeInBytes : DWORD* in/out -> LPVOID
# PathsBuffer : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型