Win32 API 日本語リファレンス
ホームSystem.WinRT.Metadata › RoIsApiContractMajorVersionPresent

RoIsApiContractMajorVersionPresent

関数
指定メジャーバージョンのAPIコントラクトが存在するかを判定する。
DLLapi-ms-win-ro-typeresolution-l1-1-1.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

// api-ms-win-ro-typeresolution-l1-1-1.dll
#include <windows.h>

HRESULT RoIsApiContractMajorVersionPresent(
    LPCWSTR name,
    WORD majorVersion,
    BOOL* present
);

パラメーター

名前方向説明
nameLPCWSTRin存在を確認するAPIコントラクト名(Unicode文字列)。
majorVersionWORDin確認するコントラクトのメジャーバージョン番号。
presentBOOL*out出力として指定メジャーバージョンが存在するか(TRUE/FALSE)を受け取るBOOLポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-ro-typeresolution-l1-1-1.dll
#include <windows.h>

HRESULT RoIsApiContractMajorVersionPresent(
    LPCWSTR name,
    WORD majorVersion,
    BOOL* present
);
[DllImport("api-ms-win-ro-typeresolution-l1-1-1.dll", ExactSpelling = true)]
static extern int RoIsApiContractMajorVersionPresent(
    [MarshalAs(UnmanagedType.LPWStr)] string name,   // LPCWSTR
    ushort majorVersion,   // WORD
    out bool present   // BOOL* out
);
<DllImport("api-ms-win-ro-typeresolution-l1-1-1.dll", ExactSpelling:=True)>
Public Shared Function RoIsApiContractMajorVersionPresent(
    <MarshalAs(UnmanagedType.LPWStr)> name As String,   ' LPCWSTR
    majorVersion As UShort,   ' WORD
    <Out> ByRef present As Boolean   ' BOOL* out
) As Integer
End Function
' name : LPCWSTR
' majorVersion : WORD
' present : BOOL* out
Declare PtrSafe Function RoIsApiContractMajorVersionPresent Lib "api-ms-win-ro-typeresolution-l1-1-1" ( _
    ByVal name As LongPtr, _
    ByVal majorVersion As Integer, _
    ByRef present As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RoIsApiContractMajorVersionPresent = ctypes.windll.LoadLibrary("api-ms-win-ro-typeresolution-l1-1-1.dll").RoIsApiContractMajorVersionPresent
RoIsApiContractMajorVersionPresent.restype = ctypes.c_int
RoIsApiContractMajorVersionPresent.argtypes = [
    wintypes.LPCWSTR,  # name : LPCWSTR
    ctypes.c_ushort,  # majorVersion : WORD
    ctypes.c_void_p,  # present : BOOL* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-ro-typeresolution-l1-1-1.dll')
RoIsApiContractMajorVersionPresent = Fiddle::Function.new(
  lib['RoIsApiContractMajorVersionPresent'],
  [
    Fiddle::TYPE_VOIDP,  # name : LPCWSTR
    -Fiddle::TYPE_SHORT,  # majorVersion : WORD
    Fiddle::TYPE_VOIDP,  # present : BOOL* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-ro-typeresolution-l1-1-1")]
extern "system" {
    fn RoIsApiContractMajorVersionPresent(
        name: *const u16,  // LPCWSTR
        majorVersion: u16,  // WORD
        present: *mut i32  // BOOL* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-ro-typeresolution-l1-1-1.dll")]
public static extern int RoIsApiContractMajorVersionPresent([MarshalAs(UnmanagedType.LPWStr)] string name, ushort majorVersion, out bool present);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-ro-typeresolution-l1-1-1_RoIsApiContractMajorVersionPresent' -Namespace Win32 -PassThru
# $api::RoIsApiContractMajorVersionPresent(name, majorVersion, present)
#uselib "api-ms-win-ro-typeresolution-l1-1-1.dll"
#func global RoIsApiContractMajorVersionPresent "RoIsApiContractMajorVersionPresent" sptr, sptr, sptr
; RoIsApiContractMajorVersionPresent name, majorVersion, varptr(present)   ; 戻り値は stat
; name : LPCWSTR -> "sptr"
; majorVersion : WORD -> "sptr"
; present : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-ro-typeresolution-l1-1-1.dll"
#cfunc global RoIsApiContractMajorVersionPresent "RoIsApiContractMajorVersionPresent" wstr, int, var
; res = RoIsApiContractMajorVersionPresent(name, majorVersion, present)
; name : LPCWSTR -> "wstr"
; majorVersion : WORD -> "int"
; present : BOOL* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT RoIsApiContractMajorVersionPresent(LPCWSTR name, WORD majorVersion, BOOL* present)
#uselib "api-ms-win-ro-typeresolution-l1-1-1.dll"
#cfunc global RoIsApiContractMajorVersionPresent "RoIsApiContractMajorVersionPresent" wstr, int, var
; res = RoIsApiContractMajorVersionPresent(name, majorVersion, present)
; name : LPCWSTR -> "wstr"
; majorVersion : WORD -> "int"
; present : BOOL* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_ro_typeresolution_l1_1_1 = windows.NewLazySystemDLL("api-ms-win-ro-typeresolution-l1-1-1.dll")
	procRoIsApiContractMajorVersionPresent = api_ms_win_ro_typeresolution_l1_1_1.NewProc("RoIsApiContractMajorVersionPresent")
)

// name (LPCWSTR), majorVersion (WORD), present (BOOL* out)
r1, _, err := procRoIsApiContractMajorVersionPresent.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(name))),
	uintptr(majorVersion),
	uintptr(present),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function RoIsApiContractMajorVersionPresent(
  name: PWideChar;   // LPCWSTR
  majorVersion: Word;   // WORD
  present: Pointer   // BOOL* out
): Integer; stdcall;
  external 'api-ms-win-ro-typeresolution-l1-1-1.dll' name 'RoIsApiContractMajorVersionPresent';
result := DllCall("api-ms-win-ro-typeresolution-l1-1-1\RoIsApiContractMajorVersionPresent"
    , "WStr", name   ; LPCWSTR
    , "UShort", majorVersion   ; WORD
    , "Ptr", present   ; BOOL* out
    , "Int")   ; return: HRESULT
●RoIsApiContractMajorVersionPresent(name, majorVersion, present) = DLL("api-ms-win-ro-typeresolution-l1-1-1.dll", "int RoIsApiContractMajorVersionPresent(char*, int, void*)")
# 呼び出し: RoIsApiContractMajorVersionPresent(name, majorVersion, present)
# name : LPCWSTR -> "char*"
# majorVersion : WORD -> "int"
# present : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef RoIsApiContractMajorVersionPresentNative = Int32 Function(Pointer<Utf16>, Uint16, Pointer<Int32>);
typedef RoIsApiContractMajorVersionPresentDart = int Function(Pointer<Utf16>, int, Pointer<Int32>);
final RoIsApiContractMajorVersionPresent = DynamicLibrary.open('api-ms-win-ro-typeresolution-l1-1-1.dll')
    .lookupFunction<RoIsApiContractMajorVersionPresentNative, RoIsApiContractMajorVersionPresentDart>('RoIsApiContractMajorVersionPresent');
// name : LPCWSTR -> Pointer<Utf16>
// majorVersion : WORD -> Uint16
// present : BOOL* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RoIsApiContractMajorVersionPresent(
  name: PWideChar;   // LPCWSTR
  majorVersion: Word;   // WORD
  present: Pointer   // BOOL* out
): Integer; stdcall;
  external 'api-ms-win-ro-typeresolution-l1-1-1.dll' name 'RoIsApiContractMajorVersionPresent';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RoIsApiContractMajorVersionPresent"
  c_RoIsApiContractMajorVersionPresent :: CWString -> Word16 -> Ptr CInt -> IO Int32
-- name : LPCWSTR -> CWString
-- majorVersion : WORD -> Word16
-- present : BOOL* out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let roisapicontractmajorversionpresent =
  foreign "RoIsApiContractMajorVersionPresent"
    ((ptr uint16_t) @-> uint16_t @-> (ptr int32_t) @-> returning int32_t)
(* name : LPCWSTR -> (ptr uint16_t) *)
(* majorVersion : WORD -> uint16_t *)
(* present : BOOL* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-ro-typeresolution-l1-1-1 (t "api-ms-win-ro-typeresolution-l1-1-1.dll"))
(cffi:use-foreign-library api-ms-win-ro-typeresolution-l1-1-1)

(cffi:defcfun ("RoIsApiContractMajorVersionPresent" ro-is-api-contract-major-version-present :convention :stdcall) :int32
  (name (:string :encoding :utf-16le))   ; LPCWSTR
  (major-version :uint16)   ; WORD
  (present :pointer))   ; BOOL* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RoIsApiContractMajorVersionPresent = Win32::API::More->new('api-ms-win-ro-typeresolution-l1-1-1',
    'int RoIsApiContractMajorVersionPresent(LPCWSTR name, WORD majorVersion, LPVOID present)');
# my $ret = $RoIsApiContractMajorVersionPresent->Call($name, $majorVersion, $present);
# name : LPCWSTR -> LPCWSTR
# majorVersion : WORD -> WORD
# present : BOOL* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。