ホーム › System.Power › GetDevicePowerState
GetDevicePowerState
関数指定デバイスが現在オン状態かどうかを取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL GetDevicePowerState(
HANDLE hDevice,
BOOL* pfOn
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hDevice | HANDLE | in |
| pfOn | BOOL* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL GetDevicePowerState(
HANDLE hDevice,
BOOL* pfOn
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool GetDevicePowerState(
IntPtr hDevice, // HANDLE
out int pfOn // BOOL* out
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetDevicePowerState(
hDevice As IntPtr, ' HANDLE
<Out> ByRef pfOn As Integer ' BOOL* out
) As Boolean
End Function' hDevice : HANDLE
' pfOn : BOOL* out
Declare PtrSafe Function GetDevicePowerState Lib "kernel32" ( _
ByVal hDevice As LongPtr, _
ByRef pfOn As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDevicePowerState = ctypes.windll.kernel32.GetDevicePowerState
GetDevicePowerState.restype = wintypes.BOOL
GetDevicePowerState.argtypes = [
wintypes.HANDLE, # hDevice : HANDLE
ctypes.c_void_p, # pfOn : BOOL* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetDevicePowerState = Fiddle::Function.new(
lib['GetDevicePowerState'],
[
Fiddle::TYPE_VOIDP, # hDevice : HANDLE
Fiddle::TYPE_VOIDP, # pfOn : BOOL* out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetDevicePowerState(
hDevice: *mut core::ffi::c_void, // HANDLE
pfOn: *mut i32 // BOOL* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool GetDevicePowerState(IntPtr hDevice, out int pfOn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetDevicePowerState' -Namespace Win32 -PassThru
# $api::GetDevicePowerState(hDevice, pfOn)#uselib "KERNEL32.dll"
#func global GetDevicePowerState "GetDevicePowerState" sptr, sptr
; GetDevicePowerState hDevice, pfOn ; 戻り値は stat
; hDevice : HANDLE -> "sptr"
; pfOn : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetDevicePowerState "GetDevicePowerState" sptr, int
; res = GetDevicePowerState(hDevice, pfOn)
; hDevice : HANDLE -> "sptr"
; pfOn : BOOL* out -> "int"; BOOL GetDevicePowerState(HANDLE hDevice, BOOL* pfOn)
#uselib "KERNEL32.dll"
#cfunc global GetDevicePowerState "GetDevicePowerState" intptr, int
; res = GetDevicePowerState(hDevice, pfOn)
; hDevice : HANDLE -> "intptr"
; pfOn : BOOL* out -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetDevicePowerState = kernel32.NewProc("GetDevicePowerState")
)
// hDevice (HANDLE), pfOn (BOOL* out)
r1, _, err := procGetDevicePowerState.Call(
uintptr(hDevice),
uintptr(pfOn),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetDevicePowerState(
hDevice: THandle; // HANDLE
pfOn: Pointer // BOOL* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetDevicePowerState';result := DllCall("KERNEL32\GetDevicePowerState"
, "Ptr", hDevice ; HANDLE
, "Ptr", pfOn ; BOOL* out
, "Int") ; return: BOOL●GetDevicePowerState(hDevice, pfOn) = DLL("KERNEL32.dll", "bool GetDevicePowerState(void*, void*)")
# 呼び出し: GetDevicePowerState(hDevice, pfOn)
# hDevice : HANDLE -> "void*"
# pfOn : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。