Win32 API 日本語リファレンス
ホームDevices.Enumeration.Pnp › SwDeviceGetLifetime

SwDeviceGetLifetime

関数
ソフトウェアデバイスの存続期間を取得する。
DLLCFGMGR32.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

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

HRESULT SwDeviceGetLifetime(
    HSWDEVICE hSwDevice,
    SW_DEVICE_LIFETIME* pLifetime
);

パラメーター

名前方向
hSwDeviceHSWDEVICEin
pLifetimeSW_DEVICE_LIFETIME*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDeviceGetLifetime(
    HSWDEVICE hSwDevice,
    SW_DEVICE_LIFETIME* pLifetime
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceGetLifetime(
    IntPtr hSwDevice,   // HSWDEVICE
    out int pLifetime   // SW_DEVICE_LIFETIME* out
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceGetLifetime(
    hSwDevice As IntPtr,   ' HSWDEVICE
    <Out> ByRef pLifetime As Integer   ' SW_DEVICE_LIFETIME* out
) As Integer
End Function
' hSwDevice : HSWDEVICE
' pLifetime : SW_DEVICE_LIFETIME* out
Declare PtrSafe Function SwDeviceGetLifetime Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByRef pLifetime As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SwDeviceGetLifetime = ctypes.windll.cfgmgr32.SwDeviceGetLifetime
SwDeviceGetLifetime.restype = ctypes.c_int
SwDeviceGetLifetime.argtypes = [
    wintypes.HANDLE,  # hSwDevice : HSWDEVICE
    ctypes.c_void_p,  # pLifetime : SW_DEVICE_LIFETIME* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceGetLifetime = Fiddle::Function.new(
  lib['SwDeviceGetLifetime'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    Fiddle::TYPE_VOIDP,  # pLifetime : SW_DEVICE_LIFETIME* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDeviceGetLifetime(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        pLifetime: *mut i32  // SW_DEVICE_LIFETIME* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDeviceGetLifetime(IntPtr hSwDevice, out int pLifetime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceGetLifetime' -Namespace Win32 -PassThru
# $api::SwDeviceGetLifetime(hSwDevice, pLifetime)
#uselib "CFGMGR32.dll"
#func global SwDeviceGetLifetime "SwDeviceGetLifetime" sptr, sptr
; SwDeviceGetLifetime hSwDevice, pLifetime   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; pLifetime : SW_DEVICE_LIFETIME* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceGetLifetime "SwDeviceGetLifetime" sptr, int
; res = SwDeviceGetLifetime(hSwDevice, pLifetime)
; hSwDevice : HSWDEVICE -> "sptr"
; pLifetime : SW_DEVICE_LIFETIME* out -> "int"
; HRESULT SwDeviceGetLifetime(HSWDEVICE hSwDevice, SW_DEVICE_LIFETIME* pLifetime)
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceGetLifetime "SwDeviceGetLifetime" intptr, int
; res = SwDeviceGetLifetime(hSwDevice, pLifetime)
; hSwDevice : HSWDEVICE -> "intptr"
; pLifetime : SW_DEVICE_LIFETIME* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDeviceGetLifetime = cfgmgr32.NewProc("SwDeviceGetLifetime")
)

// hSwDevice (HSWDEVICE), pLifetime (SW_DEVICE_LIFETIME* out)
r1, _, err := procSwDeviceGetLifetime.Call(
	uintptr(hSwDevice),
	uintptr(pLifetime),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SwDeviceGetLifetime(
  hSwDevice: THandle;   // HSWDEVICE
  pLifetime: Pointer   // SW_DEVICE_LIFETIME* out
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDeviceGetLifetime';
result := DllCall("CFGMGR32\SwDeviceGetLifetime"
    , "Ptr", hSwDevice   ; HSWDEVICE
    , "Ptr", pLifetime   ; SW_DEVICE_LIFETIME* out
    , "Int")   ; return: HRESULT
●SwDeviceGetLifetime(hSwDevice, pLifetime) = DLL("CFGMGR32.dll", "int SwDeviceGetLifetime(void*, void*)")
# 呼び出し: SwDeviceGetLifetime(hSwDevice, pLifetime)
# hSwDevice : HSWDEVICE -> "void*"
# pLifetime : SW_DEVICE_LIFETIME* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。