ActivateActCtx
関数シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL ActivateActCtx(
HANDLE hActCtx, // optional
UINT_PTR* lpCookie
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hActCtx | HANDLE | inoutoptional | アクティブにするアクティブ化コンテキストに関する情報を含む ACTCTX 構造体へのハンドルです。 |
| lpCookie | UINT_PTR* | out | 特定のアクティブ化されたアクティブ化コンテキストを一意に識別するクッキーとして機能する ULONG_PTR へのポインターです。 |
戻り値の型: BOOL
公式ドキュメント
ActivateActCtx 関数は、指定されたアクティブ化コンテキストをアクティブにします。
戻り値
関数が成功した場合は TRUE を返します。それ以外の場合は FALSE を返します。
この関数は、 GetLastError を呼び出すことで取得できるエラーを設定します。例については、 Retrieving the Last-Error Code を参照してください。エラーコードの完全な一覧については、 System Error Codes を参照してください。
解説(Remarks)
lpCookie パラメーターは、後で DeactivateActCtx に渡されます。DeactivateActCtx は、 ActivateActCtx と DeactivateActCtx の呼び出しの対応を検証し、適切なアクティブ化コンテキストが非アクティブ化されることを保証します。これは、アクティブ化コンテキストの非アクティブ化がアクティブ化とは逆の順序で行われる必要があるためです。
アクティブ化コンテキストのアクティブ化は、アクティブ化コンテキストをアクティブ化コンテキストのスタックにプッシュすることとして理解できます。この関数を通じてアクティブにしたアクティブ化コンテキストは、呼び出した任意の side-by-side API について、DLL、ウィンドウクラス、COM サーバー、タイプライブラリ、ミューテックスへのすべてのバインドをリダイレクトします。
アクティブ化コンテキストスタックの最上位の項目は、現在のスレッドのアクティブな既定のアクティブ化コンテキストです。null のアクティブ化コンテキストハンドルがスタックにプッシュされてアクティブ化されると、元のマニフェストの既定の設定が、スタックのそれより下にあるすべてのアクティブ化コンテキストを上書きします。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL ActivateActCtx(
HANDLE hActCtx, // optional
UINT_PTR* lpCookie
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ActivateActCtx(
IntPtr hActCtx, // HANDLE optional, in/out
out UIntPtr lpCookie // UINT_PTR* out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ActivateActCtx(
hActCtx As IntPtr, ' HANDLE optional, in/out
<Out> ByRef lpCookie As UIntPtr ' UINT_PTR* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hActCtx : HANDLE optional, in/out
' lpCookie : UINT_PTR* out
Declare PtrSafe Function ActivateActCtx Lib "kernel32" ( _
ByVal hActCtx As LongPtr, _
ByRef lpCookie As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ActivateActCtx = ctypes.windll.kernel32.ActivateActCtx
ActivateActCtx.restype = wintypes.BOOL
ActivateActCtx.argtypes = [
wintypes.HANDLE, # hActCtx : HANDLE optional, in/out
ctypes.POINTER(ctypes.c_size_t), # lpCookie : UINT_PTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
ActivateActCtx = Fiddle::Function.new(
lib['ActivateActCtx'],
[
Fiddle::TYPE_VOIDP, # hActCtx : HANDLE optional, in/out
Fiddle::TYPE_VOIDP, # lpCookie : UINT_PTR* out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn ActivateActCtx(
hActCtx: *mut core::ffi::c_void, // HANDLE optional, in/out
lpCookie: *mut usize // UINT_PTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool ActivateActCtx(IntPtr hActCtx, out UIntPtr lpCookie);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_ActivateActCtx' -Namespace Win32 -PassThru
# $api::ActivateActCtx(hActCtx, lpCookie)#uselib "KERNEL32.dll"
#func global ActivateActCtx "ActivateActCtx" sptr, sptr
; ActivateActCtx hActCtx, varptr(lpCookie) ; 戻り値は stat
; hActCtx : HANDLE optional, in/out -> "sptr"
; lpCookie : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll" #cfunc global ActivateActCtx "ActivateActCtx" sptr, var ; res = ActivateActCtx(hActCtx, lpCookie) ; hActCtx : HANDLE optional, in/out -> "sptr" ; lpCookie : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global ActivateActCtx "ActivateActCtx" sptr, sptr ; res = ActivateActCtx(hActCtx, varptr(lpCookie)) ; hActCtx : HANDLE optional, in/out -> "sptr" ; lpCookie : UINT_PTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL ActivateActCtx(HANDLE hActCtx, UINT_PTR* lpCookie) #uselib "KERNEL32.dll" #cfunc global ActivateActCtx "ActivateActCtx" intptr, var ; res = ActivateActCtx(hActCtx, lpCookie) ; hActCtx : HANDLE optional, in/out -> "intptr" ; lpCookie : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ActivateActCtx(HANDLE hActCtx, UINT_PTR* lpCookie) #uselib "KERNEL32.dll" #cfunc global ActivateActCtx "ActivateActCtx" intptr, intptr ; res = ActivateActCtx(hActCtx, varptr(lpCookie)) ; hActCtx : HANDLE optional, in/out -> "intptr" ; lpCookie : UINT_PTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procActivateActCtx = kernel32.NewProc("ActivateActCtx")
)
// hActCtx (HANDLE optional, in/out), lpCookie (UINT_PTR* out)
r1, _, err := procActivateActCtx.Call(
uintptr(hActCtx),
uintptr(lpCookie),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ActivateActCtx(
hActCtx: THandle; // HANDLE optional, in/out
lpCookie: Pointer // UINT_PTR* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'ActivateActCtx';result := DllCall("KERNEL32\ActivateActCtx"
, "Ptr", hActCtx ; HANDLE optional, in/out
, "Ptr", lpCookie ; UINT_PTR* out
, "Int") ; return: BOOL●ActivateActCtx(hActCtx, lpCookie) = DLL("KERNEL32.dll", "bool ActivateActCtx(void*, void*)")
# 呼び出し: ActivateActCtx(hActCtx, lpCookie)
# hActCtx : HANDLE optional, in/out -> "void*"
# lpCookie : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn ActivateActCtx(
hActCtx: ?*anyopaque, // HANDLE optional, in/out
lpCookie: [*c]usize // UINT_PTR* out
) callconv(std.os.windows.WINAPI) i32;proc ActivateActCtx(
hActCtx: pointer, # HANDLE optional, in/out
lpCookie: ptr uint # UINT_PTR* out
): int32 {.importc: "ActivateActCtx", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int ActivateActCtx(
void* hActCtx, // HANDLE optional, in/out
size_t* lpCookie // UINT_PTR* out
);ccall((:ActivateActCtx, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Csize_t}),
hActCtx, lpCookie)
# hActCtx : HANDLE optional, in/out -> Ptr{Cvoid}
# lpCookie : UINT_PTR* out -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ActivateActCtx(
void* hActCtx,
uintptr_t* lpCookie);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.ActivateActCtx(hActCtx, lpCookie)
-- hActCtx : HANDLE optional, in/out
-- lpCookie : UINT_PTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const ActivateActCtx = lib.func('__stdcall', 'ActivateActCtx', 'int32_t', ['void *', 'uintptr_t *']);
// ActivateActCtx(hActCtx, lpCookie)
// hActCtx : HANDLE optional, in/out -> 'void *'
// lpCookie : UINT_PTR* out -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
ActivateActCtx: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.ActivateActCtx(hActCtx, lpCookie)
// hActCtx : HANDLE optional, in/out -> "pointer"
// lpCookie : UINT_PTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ActivateActCtx(
void* hActCtx,
size_t* lpCookie);
C, "KERNEL32.dll");
// $ffi->ActivateActCtx(hActCtx, lpCookie);
// hActCtx : HANDLE optional, in/out
// lpCookie : UINT_PTR* out
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean ActivateActCtx(
Pointer hActCtx, // HANDLE optional, in/out
LongByReference lpCookie // UINT_PTR* out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun ActivateActCtx = ActivateActCtx(
hActCtx : Void*, # HANDLE optional, in/out
lpCookie : LibC::SizeT* # UINT_PTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ActivateActCtxNative = Int32 Function(Pointer<Void>, Pointer<UintPtr>);
typedef ActivateActCtxDart = int Function(Pointer<Void>, Pointer<UintPtr>);
final ActivateActCtx = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<ActivateActCtxNative, ActivateActCtxDart>('ActivateActCtx');
// hActCtx : HANDLE optional, in/out -> Pointer<Void>
// lpCookie : UINT_PTR* out -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ActivateActCtx(
hActCtx: THandle; // HANDLE optional, in/out
lpCookie: Pointer // UINT_PTR* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'ActivateActCtx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ActivateActCtx"
c_ActivateActCtx :: Ptr () -> Ptr CUIntPtr -> IO CInt
-- hActCtx : HANDLE optional, in/out -> Ptr ()
-- lpCookie : UINT_PTR* out -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let activateactctx =
foreign "ActivateActCtx"
((ptr void) @-> (ptr size_t) @-> returning int32_t)
(* hActCtx : HANDLE optional, in/out -> (ptr void) *)
(* lpCookie : UINT_PTR* out -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("ActivateActCtx" activate-act-ctx :convention :stdcall) :int32
(h-act-ctx :pointer) ; HANDLE optional, in/out
(lp-cookie :pointer)) ; UINT_PTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ActivateActCtx = Win32::API::More->new('KERNEL32',
'BOOL ActivateActCtx(HANDLE hActCtx, LPVOID lpCookie)');
# my $ret = $ActivateActCtx->Call($hActCtx, $lpCookie);
# hActCtx : HANDLE optional, in/out -> HANDLE
# lpCookie : UINT_PTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- s ACTCTXW
- f DeactivateActCtx — 有効化したアクティベーションコンテキストを無効化する。