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

PowerDeterminePlatformRoleEx

関数
プラットフォームの電源役割(機器種別)を判定する。
DLLPOWRPROF.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

POWER_PLATFORM_ROLE PowerDeterminePlatformRoleEx(
    POWER_PLATFORM_ROLE_VERSION Version
);

パラメーター

名前方向説明
VersionPOWER_PLATFORM_ROLE_VERSIONin

プラットフォームに対する POWER_PLATFORM_ROLE 列挙体のバージョン。このパラメーターには次のいずれかの値を指定できます。

意味
POWER_PLATFORM_ROLE_VERSION
現在のビルドターゲットに対する POWER_PLATFORM_ROLE 列挙体のバージョン。
POWER_PLATFORM_ROLE_V1
Windows 7、Windows Server 2008 R2、Windows Vista、または Windows Server 2008 に対する POWER_PLATFORM_ROLE 列挙体のバージョン。

この値を指定して PowerDeterminePlatformRoleEx を呼び出すと、Windows 7、Windows Server 2008 R2、Windows Vista、または Windows Server 2008 で PowerDeterminePlatformRole を呼び出した場合と同じ結果が返されます。

POWER_PLATFORM_ROLE_V2
Windows 8 および Windows Server 2012 に対する POWER_PLATFORM_ROLE 列挙体のバージョン。

戻り値の型: POWER_PLATFORM_ROLE

公式ドキュメント

指定されたプラットフォームのコンピューターの役割(role)を判定します。

戻り値

戻り値は、指定されたバージョンの POWER_PLATFORM_ROLE 列挙体の値のいずれかです。

解説(Remarks)

この関数は ACPI Fixed ACPI Description Table (FADT) を読み取り、OEM が推奨するコンピューターの役割を判定します。その情報が利用できない場合、関数はバッテリーを検索します。少なくとも 1 つのバッテリーが利用可能な場合、関数は PlatformRoleMobile を返します。バッテリーが 1 つも利用できない場合、関数は PlatformRoleDesktop を返します。

呼び出し元が指定したプラットフォームで OEM が推奨するコンピューターの役割がサポートされていない場合、関数はサポートされている最も近い値を返します。たとえば、タブレットデバイス上で VersionPOWER_PLATFORM_ROLE_V1 を指定して PowerDeterminePlatformRoleEx 関数を呼び出すと、PlatformRoleMobile が返されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

POWER_PLATFORM_ROLE PowerDeterminePlatformRoleEx(
    POWER_PLATFORM_ROLE_VERSION Version
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern int PowerDeterminePlatformRoleEx(
    uint Version   // POWER_PLATFORM_ROLE_VERSION
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerDeterminePlatformRoleEx(
    Version As UInteger   ' POWER_PLATFORM_ROLE_VERSION
) As Integer
End Function
' Version : POWER_PLATFORM_ROLE_VERSION
Declare PtrSafe Function PowerDeterminePlatformRoleEx Lib "powrprof" ( _
    ByVal Version As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PowerDeterminePlatformRoleEx = ctypes.windll.powrprof.PowerDeterminePlatformRoleEx
PowerDeterminePlatformRoleEx.restype = ctypes.c_int
PowerDeterminePlatformRoleEx.argtypes = [
    wintypes.DWORD,  # Version : POWER_PLATFORM_ROLE_VERSION
]
require 'fiddle'
require 'fiddle/import'

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

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerDeterminePlatformRoleEx = powrprof.NewProc("PowerDeterminePlatformRoleEx")
)

// Version (POWER_PLATFORM_ROLE_VERSION)
r1, _, err := procPowerDeterminePlatformRoleEx.Call(
	uintptr(Version),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // POWER_PLATFORM_ROLE
function PowerDeterminePlatformRoleEx(
  Version: DWORD   // POWER_PLATFORM_ROLE_VERSION
): Integer; stdcall;
  external 'POWRPROF.dll' name 'PowerDeterminePlatformRoleEx';
result := DllCall("POWRPROF\PowerDeterminePlatformRoleEx"
    , "UInt", Version   ; POWER_PLATFORM_ROLE_VERSION
    , "Int")   ; return: POWER_PLATFORM_ROLE
●PowerDeterminePlatformRoleEx(Version) = DLL("POWRPROF.dll", "int PowerDeterminePlatformRoleEx(dword)")
# 呼び出し: PowerDeterminePlatformRoleEx(Version)
# Version : POWER_PLATFORM_ROLE_VERSION -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef PowerDeterminePlatformRoleExNative = Int32 Function(Uint32);
typedef PowerDeterminePlatformRoleExDart = int Function(int);
final PowerDeterminePlatformRoleEx = DynamicLibrary.open('POWRPROF.dll')
    .lookupFunction<PowerDeterminePlatformRoleExNative, PowerDeterminePlatformRoleExDart>('PowerDeterminePlatformRoleEx');
// Version : POWER_PLATFORM_ROLE_VERSION -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PowerDeterminePlatformRoleEx(
  Version: DWORD   // POWER_PLATFORM_ROLE_VERSION
): Integer; stdcall;
  external 'POWRPROF.dll' name 'PowerDeterminePlatformRoleEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PowerDeterminePlatformRoleEx"
  c_PowerDeterminePlatformRoleEx :: Word32 -> IO Int32
-- Version : POWER_PLATFORM_ROLE_VERSION -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let powerdetermineplatformroleex =
  foreign "PowerDeterminePlatformRoleEx"
    (uint32_t @-> returning int32_t)
(* Version : POWER_PLATFORM_ROLE_VERSION -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)

(cffi:defcfun ("PowerDeterminePlatformRoleEx" power-determine-platform-role-ex :convention :stdcall) :int32
  (version :uint32))   ; POWER_PLATFORM_ROLE_VERSION
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PowerDeterminePlatformRoleEx = Win32::API::More->new('POWRPROF',
    'int PowerDeterminePlatformRoleEx(DWORD Version)');
# my $ret = $PowerDeterminePlatformRoleEx->Call($Version);
# Version : POWER_PLATFORM_ROLE_VERSION -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型