Win32 API 日本語リファレンス
ホーム › Gaming › ReleaseExclusiveCpuSets

ReleaseExclusiveCpuSets

関数
確保した専有CPUセットを解放する。
DLLapi-ms-win-gaming-expandedresources-l1-1-0.dll呼出規約winapi

シグネチャ

// api-ms-win-gaming-expandedresources-l1-1-0.dll
#include <windows.h>

HRESULT ReleaseExclusiveCpuSets(void);

パラメーターなし。戻り値: HRESULT

公式ドキュメント

CPU の排他利用をオプトアウトし、アプリがすべてのコアにアクセスできるようにします。ただし、その代償として、他のプロセスとコアを共有する必要があります。

戻り値

操作の結果。

解説(Remarks)

共有モードに移行したい場合 (たとえば、アプリがローエンド デバイス上で実行されている場合など) には、この関数を呼び出します。

この関数を呼び出した後も、アプリは GPU の優先度向上など、他のゲーム モード リソースには引き続きアクセスできます。また、HasExpandedResources による状態遷移も引き続き受け取ります。

SetProcessDefaultCpuSets と同様に、ReleaseExclusiveCpuSets はプロセス全体に適用されます。

これは、UWP デスクトップ アプリおよび Xbox アプリでのみサポートされる Win32 API です。また、expandedResources 制限付き機能 (restricted capability) が必要です。この機能は、Visual Studio で Package.appxmanifest を開き、Capabilities タブに移動することで選択できます。あるいは、ファイルのコードを直接編集することもできます。


<Package
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces=" rescap">
    ...
    <Capabilities>
        <rescap:Capability Name="expandedResources" />
    </Capabilities>
    ...
</Package>

この機能はタイトル単位で付与されます。詳細については、担当のアカウント マネージャーにお問い合わせください。この機能を使用する UWP アプリは、デスクトップを対象とする場合はストアに公開できますが、Xbox を対象とする場合は認定で拒否されます。

排他的リソースが付与されるには、アプリがフォアグラウンドにあり、フォーカスを持っている必要があります。

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

各言語での呼び出し定義

// api-ms-win-gaming-expandedresources-l1-1-0.dll
#include <windows.h>

HRESULT ReleaseExclusiveCpuSets(void);
[DllImport("api-ms-win-gaming-expandedresources-l1-1-0.dll", ExactSpelling = true)]
static extern int ReleaseExclusiveCpuSets();
<DllImport("api-ms-win-gaming-expandedresources-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function ReleaseExclusiveCpuSets() As Integer
End Function
Declare PtrSafe Function ReleaseExclusiveCpuSets Lib "api-ms-win-gaming-expandedresources-l1-1-0" () As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ReleaseExclusiveCpuSets = ctypes.windll.LoadLibrary("api-ms-win-gaming-expandedresources-l1-1-0.dll").ReleaseExclusiveCpuSets
ReleaseExclusiveCpuSets.restype = ctypes.c_int
ReleaseExclusiveCpuSets.argtypes = []
require 'fiddle'
require 'fiddle/import'

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

var (
	api_ms_win_gaming_expandedresources_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-gaming-expandedresources-l1-1-0.dll")
	procReleaseExclusiveCpuSets = api_ms_win_gaming_expandedresources_l1_1_0.NewProc("ReleaseExclusiveCpuSets")
)

r1, _, err := procReleaseExclusiveCpuSets.Call()
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ReleaseExclusiveCpuSets: Integer; stdcall;
  external 'api-ms-win-gaming-expandedresources-l1-1-0.dll' name 'ReleaseExclusiveCpuSets';
result := DllCall("api-ms-win-gaming-expandedresources-l1-1-0\ReleaseExclusiveCpuSets", "Int")
●ReleaseExclusiveCpuSets() = DLL("api-ms-win-gaming-expandedresources-l1-1-0.dll", "int ReleaseExclusiveCpuSets()")
# 呼び出し: ReleaseExclusiveCpuSets()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ReleaseExclusiveCpuSetsNative = Int32 Function();
typedef ReleaseExclusiveCpuSetsDart = int Function();
final ReleaseExclusiveCpuSets = DynamicLibrary.open('api-ms-win-gaming-expandedresources-l1-1-0.dll')
    .lookupFunction<ReleaseExclusiveCpuSetsNative, ReleaseExclusiveCpuSetsDart>('ReleaseExclusiveCpuSets');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ReleaseExclusiveCpuSets: Integer; stdcall;
  external 'api-ms-win-gaming-expandedresources-l1-1-0.dll' name 'ReleaseExclusiveCpuSets';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let releaseexclusivecpusets =
  foreign "ReleaseExclusiveCpuSets"
    (void @-> returning int32_t)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-gaming-expandedresources-l1-1-0 (t "api-ms-win-gaming-expandedresources-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-gaming-expandedresources-l1-1-0)

(cffi:defcfun ("ReleaseExclusiveCpuSets" release-exclusive-cpu-sets :convention :stdcall) :int32)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ReleaseExclusiveCpuSets = Win32::API::More->new('api-ms-win-gaming-expandedresources-l1-1-0',
    'int ReleaseExclusiveCpuSets()');
# my $ret = $ReleaseExclusiveCpuSets->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。