ホーム › Devices.DeviceAndDriverInstallation › SetupAdjustDiskSpaceListW
SetupAdjustDiskSpaceListW
関数ディスク容量リスト内の指定ドライブの空き容量を増減調整する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupAdjustDiskSpaceListW(
void* DiskSpace,
LPCWSTR DriveRoot,
LONGLONG Amount,
void* Reserved1, // optional
DWORD Reserved2 // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DiskSpace | void* | in | 調整対象のディスク領域リストのハンドル。 |
| DriveRoot | LPCWSTR | in | 領域を調整する対象ドライブのルート(Unicode)。 |
| Amount | LONGLONG | in | 増減させる空き領域のバイト数。正で増加、負で減少。 |
| Reserved1 | void* | optional | 予約済み。NULLを指定する必要がある。 |
| Reserved2 | DWORD | optional | 予約済み。0を指定する必要がある。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupAdjustDiskSpaceListW(
void* DiskSpace,
LPCWSTR DriveRoot,
LONGLONG Amount,
void* Reserved1, // optional
DWORD Reserved2 // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupAdjustDiskSpaceListW(
IntPtr DiskSpace, // void*
[MarshalAs(UnmanagedType.LPWStr)] string DriveRoot, // LPCWSTR
long Amount, // LONGLONG
IntPtr Reserved1, // void* optional
uint Reserved2 // DWORD optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupAdjustDiskSpaceListW(
DiskSpace As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> DriveRoot As String, ' LPCWSTR
Amount As Long, ' LONGLONG
Reserved1 As IntPtr, ' void* optional
Reserved2 As UInteger ' DWORD optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' DiskSpace : void*
' DriveRoot : LPCWSTR
' Amount : LONGLONG
' Reserved1 : void* optional
' Reserved2 : DWORD optional
Declare PtrSafe Function SetupAdjustDiskSpaceListW Lib "setupapi" ( _
ByVal DiskSpace As LongPtr, _
ByVal DriveRoot As LongPtr, _
ByVal Amount As LongLong, _
ByVal Reserved1 As LongPtr, _
ByVal Reserved2 As Long) As Long
' 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
SetupAdjustDiskSpaceListW = ctypes.windll.setupapi.SetupAdjustDiskSpaceListW
SetupAdjustDiskSpaceListW.restype = wintypes.BOOL
SetupAdjustDiskSpaceListW.argtypes = [
ctypes.POINTER(None), # DiskSpace : void*
wintypes.LPCWSTR, # DriveRoot : LPCWSTR
ctypes.c_longlong, # Amount : LONGLONG
ctypes.POINTER(None), # Reserved1 : void* optional
wintypes.DWORD, # Reserved2 : DWORD optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupAdjustDiskSpaceListW = Fiddle::Function.new(
lib['SetupAdjustDiskSpaceListW'],
[
Fiddle::TYPE_VOIDP, # DiskSpace : void*
Fiddle::TYPE_VOIDP, # DriveRoot : LPCWSTR
Fiddle::TYPE_LONG_LONG, # Amount : LONGLONG
Fiddle::TYPE_VOIDP, # Reserved1 : void* optional
-Fiddle::TYPE_INT, # Reserved2 : DWORD optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupAdjustDiskSpaceListW(
DiskSpace: *mut (), // void*
DriveRoot: *const u16, // LPCWSTR
Amount: i64, // LONGLONG
Reserved1: *mut (), // void* optional
Reserved2: u32 // DWORD optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupAdjustDiskSpaceListW(IntPtr DiskSpace, [MarshalAs(UnmanagedType.LPWStr)] string DriveRoot, long Amount, IntPtr Reserved1, uint Reserved2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupAdjustDiskSpaceListW' -Namespace Win32 -PassThru
# $api::SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)#uselib "SETUPAPI.dll"
#func global SetupAdjustDiskSpaceListW "SetupAdjustDiskSpaceListW" wptr, wptr, wptr, wptr, wptr
; SetupAdjustDiskSpaceListW DiskSpace, DriveRoot, Amount, Reserved1, Reserved2 ; 戻り値は stat
; DiskSpace : void* -> "wptr"
; DriveRoot : LPCWSTR -> "wptr"
; Amount : LONGLONG -> "wptr"
; Reserved1 : void* optional -> "wptr"
; Reserved2 : DWORD optional -> "wptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll"
#cfunc global SetupAdjustDiskSpaceListW "SetupAdjustDiskSpaceListW" sptr, wstr, int64, sptr, int
; res = SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
; DiskSpace : void* -> "sptr"
; DriveRoot : LPCWSTR -> "wstr"
; Amount : LONGLONG -> "int64"
; Reserved1 : void* optional -> "sptr"
; Reserved2 : DWORD optional -> "int"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。; BOOL SetupAdjustDiskSpaceListW(void* DiskSpace, LPCWSTR DriveRoot, LONGLONG Amount, void* Reserved1, DWORD Reserved2)
#uselib "SETUPAPI.dll"
#cfunc global SetupAdjustDiskSpaceListW "SetupAdjustDiskSpaceListW" intptr, wstr, int64, intptr, int
; res = SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
; DiskSpace : void* -> "intptr"
; DriveRoot : LPCWSTR -> "wstr"
; Amount : LONGLONG -> "int64"
; Reserved1 : void* optional -> "intptr"
; Reserved2 : DWORD optional -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupAdjustDiskSpaceListW = setupapi.NewProc("SetupAdjustDiskSpaceListW")
)
// DiskSpace (void*), DriveRoot (LPCWSTR), Amount (LONGLONG), Reserved1 (void* optional), Reserved2 (DWORD optional)
r1, _, err := procSetupAdjustDiskSpaceListW.Call(
uintptr(DiskSpace),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DriveRoot))),
uintptr(Amount),
uintptr(Reserved1),
uintptr(Reserved2),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupAdjustDiskSpaceListW(
DiskSpace: Pointer; // void*
DriveRoot: PWideChar; // LPCWSTR
Amount: Int64; // LONGLONG
Reserved1: Pointer; // void* optional
Reserved2: DWORD // DWORD optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupAdjustDiskSpaceListW';result := DllCall("SETUPAPI\SetupAdjustDiskSpaceListW"
, "Ptr", DiskSpace ; void*
, "WStr", DriveRoot ; LPCWSTR
, "Int64", Amount ; LONGLONG
, "Ptr", Reserved1 ; void* optional
, "UInt", Reserved2 ; DWORD optional
, "Int") ; return: BOOL●SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2) = DLL("SETUPAPI.dll", "bool SetupAdjustDiskSpaceListW(void*, char*, int64, void*, dword)")
# 呼び出し: SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
# DiskSpace : void* -> "void*"
# DriveRoot : LPCWSTR -> "char*"
# Amount : LONGLONG -> "int64"
# Reserved1 : void* optional -> "void*"
# Reserved2 : DWORD optional -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupAdjustDiskSpaceListW(
DiskSpace: ?*anyopaque, // void*
DriveRoot: [*c]const u16, // LPCWSTR
Amount: i64, // LONGLONG
Reserved1: ?*anyopaque, // void* optional
Reserved2: u32 // DWORD optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupAdjustDiskSpaceListW(
DiskSpace: pointer, # void*
DriveRoot: WideCString, # LPCWSTR
Amount: int64, # LONGLONG
Reserved1: pointer, # void* optional
Reserved2: uint32 # DWORD optional
): int32 {.importc: "SetupAdjustDiskSpaceListW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupAdjustDiskSpaceListW(
void* DiskSpace, // void*
const(wchar)* DriveRoot, // LPCWSTR
long Amount, // LONGLONG
void* Reserved1, // void* optional
uint Reserved2 // DWORD optional
);ccall((:SetupAdjustDiskSpaceListW, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Int64, Ptr{Cvoid}, UInt32),
DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
# DiskSpace : void* -> Ptr{Cvoid}
# DriveRoot : LPCWSTR -> Cwstring
# Amount : LONGLONG -> Int64
# Reserved1 : void* optional -> Ptr{Cvoid}
# Reserved2 : DWORD optional -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupAdjustDiskSpaceListW(
void* DiskSpace,
const uint16_t* DriveRoot,
int64_t Amount,
void* Reserved1,
uint32_t Reserved2);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
-- DiskSpace : void*
-- DriveRoot : LPCWSTR
-- Amount : LONGLONG
-- Reserved1 : void* optional
-- Reserved2 : DWORD optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupAdjustDiskSpaceListW = lib.func('__stdcall', 'SetupAdjustDiskSpaceListW', 'int32_t', ['void *', 'str16', 'int64_t', 'void *', 'uint32_t']);
// SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
// DiskSpace : void* -> 'void *'
// DriveRoot : LPCWSTR -> 'str16'
// Amount : LONGLONG -> 'int64_t'
// Reserved1 : void* optional -> 'void *'
// Reserved2 : DWORD optional -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupAdjustDiskSpaceListW: { parameters: ["pointer", "buffer", "i64", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2)
// DiskSpace : void* -> "pointer"
// DriveRoot : LPCWSTR -> "buffer"
// Amount : LONGLONG -> "i64"
// Reserved1 : void* optional -> "pointer"
// Reserved2 : DWORD optional -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupAdjustDiskSpaceListW(
void* DiskSpace,
const uint16_t* DriveRoot,
int64_t Amount,
void* Reserved1,
uint32_t Reserved2);
C, "SETUPAPI.dll");
// $ffi->SetupAdjustDiskSpaceListW(DiskSpace, DriveRoot, Amount, Reserved1, Reserved2);
// DiskSpace : void*
// DriveRoot : LPCWSTR
// Amount : LONGLONG
// Reserved1 : void* optional
// Reserved2 : DWORD optional
// 構造体/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.UNICODE_OPTIONS);
boolean SetupAdjustDiskSpaceListW(
Pointer DiskSpace, // void*
WString DriveRoot, // LPCWSTR
long Amount, // LONGLONG
Pointer Reserved1, // void* optional
int Reserved2 // DWORD optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupAdjustDiskSpaceListW = SetupAdjustDiskSpaceListW(
DiskSpace : Void*, # void*
DriveRoot : UInt16*, # LPCWSTR
Amount : Int64, # LONGLONG
Reserved1 : Void*, # void* optional
Reserved2 : UInt32 # DWORD optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupAdjustDiskSpaceListWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int64, Pointer<Void>, Uint32);
typedef SetupAdjustDiskSpaceListWDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, int);
final SetupAdjustDiskSpaceListW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupAdjustDiskSpaceListWNative, SetupAdjustDiskSpaceListWDart>('SetupAdjustDiskSpaceListW');
// DiskSpace : void* -> Pointer<Void>
// DriveRoot : LPCWSTR -> Pointer<Utf16>
// Amount : LONGLONG -> Int64
// Reserved1 : void* optional -> Pointer<Void>
// Reserved2 : DWORD optional -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupAdjustDiskSpaceListW(
DiskSpace: Pointer; // void*
DriveRoot: PWideChar; // LPCWSTR
Amount: Int64; // LONGLONG
Reserved1: Pointer; // void* optional
Reserved2: DWORD // DWORD optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupAdjustDiskSpaceListW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupAdjustDiskSpaceListW"
c_SetupAdjustDiskSpaceListW :: Ptr () -> CWString -> Int64 -> Ptr () -> Word32 -> IO CInt
-- DiskSpace : void* -> Ptr ()
-- DriveRoot : LPCWSTR -> CWString
-- Amount : LONGLONG -> Int64
-- Reserved1 : void* optional -> Ptr ()
-- Reserved2 : DWORD optional -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupadjustdiskspacelistw =
foreign "SetupAdjustDiskSpaceListW"
((ptr void) @-> (ptr uint16_t) @-> int64_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* DiskSpace : void* -> (ptr void) *)
(* DriveRoot : LPCWSTR -> (ptr uint16_t) *)
(* Amount : LONGLONG -> int64_t *)
(* Reserved1 : void* optional -> (ptr void) *)
(* Reserved2 : DWORD optional -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupAdjustDiskSpaceListW" setup-adjust-disk-space-list-w :convention :stdcall) :int32
(disk-space :pointer) ; void*
(drive-root (:string :encoding :utf-16le)) ; LPCWSTR
(amount :int64) ; LONGLONG
(reserved1 :pointer) ; void* optional
(reserved2 :uint32)) ; DWORD optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupAdjustDiskSpaceListW = Win32::API::More->new('SETUPAPI',
'BOOL SetupAdjustDiskSpaceListW(LPVOID DiskSpace, LPCWSTR DriveRoot, INT64 Amount, LPVOID Reserved1, DWORD Reserved2)');
# my $ret = $SetupAdjustDiskSpaceListW->Call($DiskSpace, $DriveRoot, $Amount, $Reserved1, $Reserved2);
# DiskSpace : void* -> LPVOID
# DriveRoot : LPCWSTR -> LPCWSTR
# Amount : LONGLONG -> INT64
# Reserved1 : void* optional -> LPVOID
# Reserved2 : DWORD optional -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupAdjustDiskSpaceListA (ANSI版) — ディスク容量リスト内の指定ドライブの空き容量を増減調整する。