Win32 API 日本語リファレンス
ホームSystem.Power › CallNtPowerInformation

CallNtPowerInformation

関数
電源情報の取得や電源設定の変更を行う。
DLLPOWRPROF.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

NTSTATUS CallNtPowerInformation(
    POWER_INFORMATION_LEVEL InformationLevel,
    void* InputBuffer,   // optional
    DWORD InputBufferLength,
    void* OutputBuffer,   // optional
    DWORD OutputBufferLength
);

パラメーター

名前方向
InformationLevelPOWER_INFORMATION_LEVELin
InputBuffervoid*inoptional
InputBufferLengthDWORDin
OutputBuffervoid*outoptional
OutputBufferLengthDWORDin

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS CallNtPowerInformation(
    POWER_INFORMATION_LEVEL InformationLevel,
    void* InputBuffer,   // optional
    DWORD InputBufferLength,
    void* OutputBuffer,   // optional
    DWORD OutputBufferLength
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern int CallNtPowerInformation(
    int InformationLevel,   // POWER_INFORMATION_LEVEL
    IntPtr InputBuffer,   // void* optional
    uint InputBufferLength,   // DWORD
    IntPtr OutputBuffer,   // void* optional, out
    uint OutputBufferLength   // DWORD
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function CallNtPowerInformation(
    InformationLevel As Integer,   ' POWER_INFORMATION_LEVEL
    InputBuffer As IntPtr,   ' void* optional
    InputBufferLength As UInteger,   ' DWORD
    OutputBuffer As IntPtr,   ' void* optional, out
    OutputBufferLength As UInteger   ' DWORD
) As Integer
End Function
' InformationLevel : POWER_INFORMATION_LEVEL
' InputBuffer : void* optional
' InputBufferLength : DWORD
' OutputBuffer : void* optional, out
' OutputBufferLength : DWORD
Declare PtrSafe Function CallNtPowerInformation Lib "powrprof" ( _
    ByVal InformationLevel As Long, _
    ByVal InputBuffer As LongPtr, _
    ByVal InputBufferLength As Long, _
    ByVal OutputBuffer As LongPtr, _
    ByVal OutputBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CallNtPowerInformation = ctypes.windll.powrprof.CallNtPowerInformation
CallNtPowerInformation.restype = ctypes.c_int
CallNtPowerInformation.argtypes = [
    ctypes.c_int,  # InformationLevel : POWER_INFORMATION_LEVEL
    ctypes.POINTER(None),  # InputBuffer : void* optional
    wintypes.DWORD,  # InputBufferLength : DWORD
    ctypes.POINTER(None),  # OutputBuffer : void* optional, out
    wintypes.DWORD,  # OutputBufferLength : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('POWRPROF.dll')
CallNtPowerInformation = Fiddle::Function.new(
  lib['CallNtPowerInformation'],
  [
    Fiddle::TYPE_INT,  # InformationLevel : POWER_INFORMATION_LEVEL
    Fiddle::TYPE_VOIDP,  # InputBuffer : void* optional
    -Fiddle::TYPE_INT,  # InputBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # OutputBuffer : void* optional, out
    -Fiddle::TYPE_INT,  # OutputBufferLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "powrprof")]
extern "system" {
    fn CallNtPowerInformation(
        InformationLevel: i32,  // POWER_INFORMATION_LEVEL
        InputBuffer: *mut (),  // void* optional
        InputBufferLength: u32,  // DWORD
        OutputBuffer: *mut (),  // void* optional, out
        OutputBufferLength: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("POWRPROF.dll")]
public static extern int CallNtPowerInformation(int InformationLevel, IntPtr InputBuffer, uint InputBufferLength, IntPtr OutputBuffer, uint OutputBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_CallNtPowerInformation' -Namespace Win32 -PassThru
# $api::CallNtPowerInformation(InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength)
#uselib "POWRPROF.dll"
#func global CallNtPowerInformation "CallNtPowerInformation" sptr, sptr, sptr, sptr, sptr
; CallNtPowerInformation InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength   ; 戻り値は stat
; InformationLevel : POWER_INFORMATION_LEVEL -> "sptr"
; InputBuffer : void* optional -> "sptr"
; InputBufferLength : DWORD -> "sptr"
; OutputBuffer : void* optional, out -> "sptr"
; OutputBufferLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "POWRPROF.dll"
#cfunc global CallNtPowerInformation "CallNtPowerInformation" int, sptr, int, sptr, int
; res = CallNtPowerInformation(InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength)
; InformationLevel : POWER_INFORMATION_LEVEL -> "int"
; InputBuffer : void* optional -> "sptr"
; InputBufferLength : DWORD -> "int"
; OutputBuffer : void* optional, out -> "sptr"
; OutputBufferLength : DWORD -> "int"
; NTSTATUS CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, void* InputBuffer, DWORD InputBufferLength, void* OutputBuffer, DWORD OutputBufferLength)
#uselib "POWRPROF.dll"
#cfunc global CallNtPowerInformation "CallNtPowerInformation" int, intptr, int, intptr, int
; res = CallNtPowerInformation(InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength)
; InformationLevel : POWER_INFORMATION_LEVEL -> "int"
; InputBuffer : void* optional -> "intptr"
; InputBufferLength : DWORD -> "int"
; OutputBuffer : void* optional, out -> "intptr"
; OutputBufferLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procCallNtPowerInformation = powrprof.NewProc("CallNtPowerInformation")
)

// InformationLevel (POWER_INFORMATION_LEVEL), InputBuffer (void* optional), InputBufferLength (DWORD), OutputBuffer (void* optional, out), OutputBufferLength (DWORD)
r1, _, err := procCallNtPowerInformation.Call(
	uintptr(InformationLevel),
	uintptr(InputBuffer),
	uintptr(InputBufferLength),
	uintptr(OutputBuffer),
	uintptr(OutputBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function CallNtPowerInformation(
  InformationLevel: Integer;   // POWER_INFORMATION_LEVEL
  InputBuffer: Pointer;   // void* optional
  InputBufferLength: DWORD;   // DWORD
  OutputBuffer: Pointer;   // void* optional, out
  OutputBufferLength: DWORD   // DWORD
): Integer; stdcall;
  external 'POWRPROF.dll' name 'CallNtPowerInformation';
result := DllCall("POWRPROF\CallNtPowerInformation"
    , "Int", InformationLevel   ; POWER_INFORMATION_LEVEL
    , "Ptr", InputBuffer   ; void* optional
    , "UInt", InputBufferLength   ; DWORD
    , "Ptr", OutputBuffer   ; void* optional, out
    , "UInt", OutputBufferLength   ; DWORD
    , "Int")   ; return: NTSTATUS
●CallNtPowerInformation(InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength) = DLL("POWRPROF.dll", "int CallNtPowerInformation(int, void*, dword, void*, dword)")
# 呼び出し: CallNtPowerInformation(InformationLevel, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength)
# InformationLevel : POWER_INFORMATION_LEVEL -> "int"
# InputBuffer : void* optional -> "void*"
# InputBufferLength : DWORD -> "dword"
# OutputBuffer : void* optional, out -> "void*"
# OutputBufferLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。