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

QueryProtectedPolicy

関数
保護ポリシー値をGUID指定で問い合わせる。
DLLKERNEL32.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

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

BOOL QueryProtectedPolicy(
    const GUID* PolicyGuid,
    UINT_PTR* PolicyValue
);

パラメーター

名前方向
PolicyGuidGUID*in
PolicyValueUINT_PTR*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL QueryProtectedPolicy(
    const GUID* PolicyGuid,
    UINT_PTR* PolicyValue
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool QueryProtectedPolicy(
    ref Guid PolicyGuid,   // GUID*
    out UIntPtr PolicyValue   // UINT_PTR* out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function QueryProtectedPolicy(
    ByRef PolicyGuid As Guid,   ' GUID*
    <Out> ByRef PolicyValue As UIntPtr   ' UINT_PTR* out
) As Boolean
End Function
' PolicyGuid : GUID*
' PolicyValue : UINT_PTR* out
Declare PtrSafe Function QueryProtectedPolicy Lib "kernel32" ( _
    ByVal PolicyGuid As LongPtr, _
    ByRef PolicyValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

QueryProtectedPolicy = ctypes.windll.kernel32.QueryProtectedPolicy
QueryProtectedPolicy.restype = wintypes.BOOL
QueryProtectedPolicy.argtypes = [
    ctypes.c_void_p,  # PolicyGuid : GUID*
    ctypes.POINTER(ctypes.c_size_t),  # PolicyValue : UINT_PTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
QueryProtectedPolicy = Fiddle::Function.new(
  lib['QueryProtectedPolicy'],
  [
    Fiddle::TYPE_VOIDP,  # PolicyGuid : GUID*
    Fiddle::TYPE_VOIDP,  # PolicyValue : UINT_PTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn QueryProtectedPolicy(
        PolicyGuid: *const GUID,  // GUID*
        PolicyValue: *mut usize  // UINT_PTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool QueryProtectedPolicy(ref Guid PolicyGuid, out UIntPtr PolicyValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryProtectedPolicy' -Namespace Win32 -PassThru
# $api::QueryProtectedPolicy(PolicyGuid, PolicyValue)
#uselib "KERNEL32.dll"
#func global QueryProtectedPolicy "QueryProtectedPolicy" sptr, sptr
; QueryProtectedPolicy varptr(PolicyGuid), varptr(PolicyValue)   ; 戻り値は stat
; PolicyGuid : GUID* -> "sptr"
; PolicyValue : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global QueryProtectedPolicy "QueryProtectedPolicy" var, var
; res = QueryProtectedPolicy(PolicyGuid, PolicyValue)
; PolicyGuid : GUID* -> "var"
; PolicyValue : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryProtectedPolicy(GUID* PolicyGuid, UINT_PTR* PolicyValue)
#uselib "KERNEL32.dll"
#cfunc global QueryProtectedPolicy "QueryProtectedPolicy" var, var
; res = QueryProtectedPolicy(PolicyGuid, PolicyValue)
; PolicyGuid : GUID* -> "var"
; PolicyValue : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procQueryProtectedPolicy = kernel32.NewProc("QueryProtectedPolicy")
)

// PolicyGuid (GUID*), PolicyValue (UINT_PTR* out)
r1, _, err := procQueryProtectedPolicy.Call(
	uintptr(PolicyGuid),
	uintptr(PolicyValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function QueryProtectedPolicy(
  PolicyGuid: PGUID;   // GUID*
  PolicyValue: Pointer   // UINT_PTR* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'QueryProtectedPolicy';
result := DllCall("KERNEL32\QueryProtectedPolicy"
    , "Ptr", PolicyGuid   ; GUID*
    , "Ptr", PolicyValue   ; UINT_PTR* out
    , "Int")   ; return: BOOL
●QueryProtectedPolicy(PolicyGuid, PolicyValue) = DLL("KERNEL32.dll", "bool QueryProtectedPolicy(void*, void*)")
# 呼び出し: QueryProtectedPolicy(PolicyGuid, PolicyValue)
# PolicyGuid : GUID* -> "void*"
# PolicyValue : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。