Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupDiDestroyDeviceInfoList

SetupDiDestroyDeviceInfoList

関数
デバイス情報セットを破棄しリソースを解放する。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiDestroyDeviceInfoList(
    HDEVINFO DeviceInfoSet
);

パラメーター

名前方向説明
DeviceInfoSetHDEVINFOin破棄して解放するデバイス情報セットのハンドル。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiDestroyDeviceInfoList(
    HDEVINFO DeviceInfoSet
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiDestroyDeviceInfoList(
    IntPtr DeviceInfoSet   // HDEVINFO
);
<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiDestroyDeviceInfoList(
    DeviceInfoSet As IntPtr   ' HDEVINFO
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' DeviceInfoSet : HDEVINFO
Declare PtrSafe Function SetupDiDestroyDeviceInfoList Lib "setupapi" ( _
    ByVal DeviceInfoSet As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiDestroyDeviceInfoList = ctypes.windll.setupapi.SetupDiDestroyDeviceInfoList
SetupDiDestroyDeviceInfoList.restype = wintypes.BOOL
SetupDiDestroyDeviceInfoList.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiDestroyDeviceInfoList = Fiddle::Function.new(
  lib['SetupDiDestroyDeviceInfoList'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiDestroyDeviceInfoList(
        DeviceInfoSet: isize  // HDEVINFO
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true)]
public static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiDestroyDeviceInfoList' -Namespace Win32 -PassThru
# $api::SetupDiDestroyDeviceInfoList(DeviceInfoSet)
#uselib "SETUPAPI.dll"
#func global SetupDiDestroyDeviceInfoList "SetupDiDestroyDeviceInfoList" sptr
; SetupDiDestroyDeviceInfoList DeviceInfoSet   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SETUPAPI.dll"
#cfunc global SetupDiDestroyDeviceInfoList "SetupDiDestroyDeviceInfoList" sptr
; res = SetupDiDestroyDeviceInfoList(DeviceInfoSet)
; DeviceInfoSet : HDEVINFO -> "sptr"
; BOOL SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiDestroyDeviceInfoList "SetupDiDestroyDeviceInfoList" intptr
; res = SetupDiDestroyDeviceInfoList(DeviceInfoSet)
; DeviceInfoSet : HDEVINFO -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiDestroyDeviceInfoList = setupapi.NewProc("SetupDiDestroyDeviceInfoList")
)

// DeviceInfoSet (HDEVINFO)
r1, _, err := procSetupDiDestroyDeviceInfoList.Call(
	uintptr(DeviceInfoSet),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiDestroyDeviceInfoList(
  DeviceInfoSet: NativeInt   // HDEVINFO
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiDestroyDeviceInfoList';
result := DllCall("SETUPAPI\SetupDiDestroyDeviceInfoList"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Int")   ; return: BOOL
●SetupDiDestroyDeviceInfoList(DeviceInfoSet) = DLL("SETUPAPI.dll", "bool SetupDiDestroyDeviceInfoList(int)")
# 呼び出し: SetupDiDestroyDeviceInfoList(DeviceInfoSet)
# DeviceInfoSet : HDEVINFO -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupDiDestroyDeviceInfoList(
    DeviceInfoSet: isize // HDEVINFO
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiDestroyDeviceInfoList(
    DeviceInfoSet: int  # HDEVINFO
): int32 {.importc: "SetupDiDestroyDeviceInfoList", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiDestroyDeviceInfoList(
    ptrdiff_t DeviceInfoSet   // HDEVINFO
);
ccall((:SetupDiDestroyDeviceInfoList, "SETUPAPI.dll"), stdcall, Int32,
      (Int,),
      DeviceInfoSet)
# DeviceInfoSet : HDEVINFO -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiDestroyDeviceInfoList(
    intptr_t DeviceInfoSet);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiDestroyDeviceInfoList(DeviceInfoSet)
-- DeviceInfoSet : HDEVINFO
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiDestroyDeviceInfoList = lib.func('__stdcall', 'SetupDiDestroyDeviceInfoList', 'int32_t', ['intptr_t']);
// SetupDiDestroyDeviceInfoList(DeviceInfoSet)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiDestroyDeviceInfoList: { parameters: ["isize"], result: "i32" },
});
// lib.symbols.SetupDiDestroyDeviceInfoList(DeviceInfoSet)
// DeviceInfoSet : HDEVINFO -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiDestroyDeviceInfoList(
    intptr_t DeviceInfoSet);
C, "SETUPAPI.dll");
// $ffi->SetupDiDestroyDeviceInfoList(DeviceInfoSet);
// DeviceInfoSet : HDEVINFO
// 構造体/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);
    boolean SetupDiDestroyDeviceInfoList(
        long DeviceInfoSet   // HDEVINFO
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiDestroyDeviceInfoList = SetupDiDestroyDeviceInfoList(
    DeviceInfoSet : LibC::SSizeT   # HDEVINFO
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiDestroyDeviceInfoListNative = Int32 Function(IntPtr);
typedef SetupDiDestroyDeviceInfoListDart = int Function(int);
final SetupDiDestroyDeviceInfoList = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiDestroyDeviceInfoListNative, SetupDiDestroyDeviceInfoListDart>('SetupDiDestroyDeviceInfoList');
// DeviceInfoSet : HDEVINFO -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupDiDestroyDeviceInfoList(
  DeviceInfoSet: NativeInt   // HDEVINFO
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiDestroyDeviceInfoList';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiDestroyDeviceInfoList"
  c_SetupDiDestroyDeviceInfoList :: CIntPtr -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdidestroydeviceinfolist =
  foreign "SetupDiDestroyDeviceInfoList"
    (intptr_t @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiDestroyDeviceInfoList" setup-di-destroy-device-info-list :convention :stdcall) :int32
  (device-info-set :int64))   ; HDEVINFO
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiDestroyDeviceInfoList = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiDestroyDeviceInfoList(LPARAM DeviceInfoSet)');
# my $ret = $SetupDiDestroyDeviceInfoList->Call($DeviceInfoSet);
# DeviceInfoSet : HDEVINFO -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。