ホーム › System.Ole › LoadRegTypeLib
LoadRegTypeLib
関数GUIDとバージョンで登録済みタイプライブラリを検索して読み込む。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT LoadRegTypeLib(
const GUID* rguid,
WORD wVerMajor,
WORD wVerMinor,
DWORD lcid,
ITypeLib** pptlib
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| rguid | GUID* | in | ライブラリの GUID。 |
| wVerMajor | WORD | in | ライブラリのメジャーバージョン。 |
| wVerMinor | WORD | in | ライブラリのマイナーバージョン。 |
| lcid | DWORD | in | ライブラリの各国語コード。 |
| pptlib | ITypeLib** | out | 読み込まれたタイプライブラリ。 |
戻り値の型: HRESULT
公式ドキュメント
レジストリの情報を使用してタイプライブラリを読み込みます。
戻り値
この関数は次のいずれかの値を返します。
| 戻り値 | 説明 |
|---|---|
| 成功しました。 | |
| 1 つ以上の引数が無効です。 | |
| 操作を完了するためのメモリが不足しています。 | |
| 関数はファイルに書き込めませんでした。 | |
| タイプライブラリを開けませんでした。 | |
| 関数はファイルから読み取れませんでした。 | |
| タイプライブラリの形式が古いものです。 | |
| LCID が OLE がサポートする DLL 内に見つかりませんでした。 | |
| タイプライブラリまたは DLL を読み込めませんでした。 |
解説(Remarks)
LoadRegTypeLib 関数は、ファイルの読み込みを LoadTypeLib に委譲します。
LoadRegTypeLib は、要求されたバージョン番号をシステムレジストリ内のものと比較し、次のいずれかの動作を行います。
- 登録済みのライブラリのうち 1 つが、要求されたメジャーバージョン番号とマイナーバージョン番号の両方に完全に一致する場合、そのタイプライブラリが読み込まれます。
- 1 つ以上の登録済みタイプライブラリが、要求されたメジャーバージョン番号に完全に一致し、かつ要求されたものより大きいマイナーバージョン番号を持つ場合、最も大きいマイナーバージョン番号を持つものが読み込まれます。
- 登録済みタイプライブラリのいずれも要求されたメジャーバージョン番号に完全に一致しない場合(または、メジャーバージョン番号に完全に一致するもののうち、要求されたマイナーバージョン番号以上のマイナーバージョン番号を持つものがない場合)、LoadRegTypeLib はエラーを返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT LoadRegTypeLib(
const GUID* rguid,
WORD wVerMajor,
WORD wVerMinor,
DWORD lcid,
ITypeLib** pptlib
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int LoadRegTypeLib(
ref Guid rguid, // GUID*
ushort wVerMajor, // WORD
ushort wVerMinor, // WORD
uint lcid, // DWORD
IntPtr pptlib // ITypeLib** out
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function LoadRegTypeLib(
ByRef rguid As Guid, ' GUID*
wVerMajor As UShort, ' WORD
wVerMinor As UShort, ' WORD
lcid As UInteger, ' DWORD
pptlib As IntPtr ' ITypeLib** out
) As Integer
End Function' rguid : GUID*
' wVerMajor : WORD
' wVerMinor : WORD
' lcid : DWORD
' pptlib : ITypeLib** out
Declare PtrSafe Function LoadRegTypeLib Lib "oleaut32" ( _
ByVal rguid As LongPtr, _
ByVal wVerMajor As Integer, _
ByVal wVerMinor As Integer, _
ByVal lcid As Long, _
ByVal pptlib As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LoadRegTypeLib = ctypes.windll.oleaut32.LoadRegTypeLib
LoadRegTypeLib.restype = ctypes.c_int
LoadRegTypeLib.argtypes = [
ctypes.c_void_p, # rguid : GUID*
ctypes.c_ushort, # wVerMajor : WORD
ctypes.c_ushort, # wVerMinor : WORD
wintypes.DWORD, # lcid : DWORD
ctypes.c_void_p, # pptlib : ITypeLib** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
LoadRegTypeLib = Fiddle::Function.new(
lib['LoadRegTypeLib'],
[
Fiddle::TYPE_VOIDP, # rguid : GUID*
-Fiddle::TYPE_SHORT, # wVerMajor : WORD
-Fiddle::TYPE_SHORT, # wVerMinor : WORD
-Fiddle::TYPE_INT, # lcid : DWORD
Fiddle::TYPE_VOIDP, # pptlib : ITypeLib** out
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn LoadRegTypeLib(
rguid: *const GUID, // GUID*
wVerMajor: u16, // WORD
wVerMinor: u16, // WORD
lcid: u32, // DWORD
pptlib: *mut *mut core::ffi::c_void // ITypeLib** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int LoadRegTypeLib(ref Guid rguid, ushort wVerMajor, ushort wVerMinor, uint lcid, IntPtr pptlib);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_LoadRegTypeLib' -Namespace Win32 -PassThru
# $api::LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib)#uselib "OLEAUT32.dll"
#func global LoadRegTypeLib "LoadRegTypeLib" sptr, sptr, sptr, sptr, sptr
; LoadRegTypeLib varptr(rguid), wVerMajor, wVerMinor, lcid, pptlib ; 戻り値は stat
; rguid : GUID* -> "sptr"
; wVerMajor : WORD -> "sptr"
; wVerMinor : WORD -> "sptr"
; lcid : DWORD -> "sptr"
; pptlib : ITypeLib** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLEAUT32.dll" #cfunc global LoadRegTypeLib "LoadRegTypeLib" var, int, int, int, sptr ; res = LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib) ; rguid : GUID* -> "var" ; wVerMajor : WORD -> "int" ; wVerMinor : WORD -> "int" ; lcid : DWORD -> "int" ; pptlib : ITypeLib** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLEAUT32.dll" #cfunc global LoadRegTypeLib "LoadRegTypeLib" sptr, int, int, int, sptr ; res = LoadRegTypeLib(varptr(rguid), wVerMajor, wVerMinor, lcid, pptlib) ; rguid : GUID* -> "sptr" ; wVerMajor : WORD -> "int" ; wVerMinor : WORD -> "int" ; lcid : DWORD -> "int" ; pptlib : ITypeLib** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT LoadRegTypeLib(GUID* rguid, WORD wVerMajor, WORD wVerMinor, DWORD lcid, ITypeLib** pptlib) #uselib "OLEAUT32.dll" #cfunc global LoadRegTypeLib "LoadRegTypeLib" var, int, int, int, intptr ; res = LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib) ; rguid : GUID* -> "var" ; wVerMajor : WORD -> "int" ; wVerMinor : WORD -> "int" ; lcid : DWORD -> "int" ; pptlib : ITypeLib** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT LoadRegTypeLib(GUID* rguid, WORD wVerMajor, WORD wVerMinor, DWORD lcid, ITypeLib** pptlib) #uselib "OLEAUT32.dll" #cfunc global LoadRegTypeLib "LoadRegTypeLib" intptr, int, int, int, intptr ; res = LoadRegTypeLib(varptr(rguid), wVerMajor, wVerMinor, lcid, pptlib) ; rguid : GUID* -> "intptr" ; wVerMajor : WORD -> "int" ; wVerMinor : WORD -> "int" ; lcid : DWORD -> "int" ; pptlib : ITypeLib** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procLoadRegTypeLib = oleaut32.NewProc("LoadRegTypeLib")
)
// rguid (GUID*), wVerMajor (WORD), wVerMinor (WORD), lcid (DWORD), pptlib (ITypeLib** out)
r1, _, err := procLoadRegTypeLib.Call(
uintptr(rguid),
uintptr(wVerMajor),
uintptr(wVerMinor),
uintptr(lcid),
uintptr(pptlib),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction LoadRegTypeLib(
rguid: PGUID; // GUID*
wVerMajor: Word; // WORD
wVerMinor: Word; // WORD
lcid: DWORD; // DWORD
pptlib: Pointer // ITypeLib** out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'LoadRegTypeLib';result := DllCall("OLEAUT32\LoadRegTypeLib"
, "Ptr", rguid ; GUID*
, "UShort", wVerMajor ; WORD
, "UShort", wVerMinor ; WORD
, "UInt", lcid ; DWORD
, "Ptr", pptlib ; ITypeLib** out
, "Int") ; return: HRESULT●LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib) = DLL("OLEAUT32.dll", "int LoadRegTypeLib(void*, int, int, dword, void*)")
# 呼び出し: LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib)
# rguid : GUID* -> "void*"
# wVerMajor : WORD -> "int"
# wVerMinor : WORD -> "int"
# lcid : DWORD -> "dword"
# pptlib : ITypeLib** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "oleaut32" fn LoadRegTypeLib(
rguid: [*c]GUID, // GUID*
wVerMajor: u16, // WORD
wVerMinor: u16, // WORD
lcid: u32, // DWORD
pptlib: ?*anyopaque // ITypeLib** out
) callconv(std.os.windows.WINAPI) i32;proc LoadRegTypeLib(
rguid: ptr GUID, # GUID*
wVerMajor: uint16, # WORD
wVerMinor: uint16, # WORD
lcid: uint32, # DWORD
pptlib: pointer # ITypeLib** out
): int32 {.importc: "LoadRegTypeLib", stdcall, dynlib: "OLEAUT32.dll".}pragma(lib, "oleaut32");
extern(Windows)
int LoadRegTypeLib(
GUID* rguid, // GUID*
ushort wVerMajor, // WORD
ushort wVerMinor, // WORD
uint lcid, // DWORD
void* pptlib // ITypeLib** out
);ccall((:LoadRegTypeLib, "OLEAUT32.dll"), stdcall, Int32,
(Ptr{GUID}, UInt16, UInt16, UInt32, Ptr{Cvoid}),
rguid, wVerMajor, wVerMinor, lcid, pptlib)
# rguid : GUID* -> Ptr{GUID}
# wVerMajor : WORD -> UInt16
# wVerMinor : WORD -> UInt16
# lcid : DWORD -> UInt32
# pptlib : ITypeLib** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LoadRegTypeLib(
void* rguid,
uint16_t wVerMajor,
uint16_t wVerMinor,
uint32_t lcid,
void* pptlib);
]]
local oleaut32 = ffi.load("oleaut32")
-- oleaut32.LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib)
-- rguid : GUID*
-- wVerMajor : WORD
-- wVerMinor : WORD
-- lcid : DWORD
-- pptlib : ITypeLib** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLEAUT32.dll');
const LoadRegTypeLib = lib.func('__stdcall', 'LoadRegTypeLib', 'int32_t', ['void *', 'uint16_t', 'uint16_t', 'uint32_t', 'void *']);
// LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib)
// rguid : GUID* -> 'void *'
// wVerMajor : WORD -> 'uint16_t'
// wVerMinor : WORD -> 'uint16_t'
// lcid : DWORD -> 'uint32_t'
// pptlib : ITypeLib** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLEAUT32.dll", {
LoadRegTypeLib: { parameters: ["pointer", "u16", "u16", "u32", "pointer"], result: "i32" },
});
// lib.symbols.LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib)
// rguid : GUID* -> "pointer"
// wVerMajor : WORD -> "u16"
// wVerMinor : WORD -> "u16"
// lcid : DWORD -> "u32"
// pptlib : ITypeLib** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LoadRegTypeLib(
void* rguid,
uint16_t wVerMajor,
uint16_t wVerMinor,
uint32_t lcid,
void* pptlib);
C, "OLEAUT32.dll");
// $ffi->LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, pptlib);
// rguid : GUID*
// wVerMajor : WORD
// wVerMinor : WORD
// lcid : DWORD
// pptlib : ITypeLib** 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 Oleaut32 extends StdCallLibrary {
Oleaut32 INSTANCE = Native.load("oleaut32", Oleaut32.class);
int LoadRegTypeLib(
Pointer rguid, // GUID*
short wVerMajor, // WORD
short wVerMinor, // WORD
int lcid, // DWORD
Pointer pptlib // ITypeLib** out
);
}@[Link("oleaut32")]
lib LibOLEAUT32
fun LoadRegTypeLib = LoadRegTypeLib(
rguid : GUID*, # GUID*
wVerMajor : UInt16, # WORD
wVerMinor : UInt16, # WORD
lcid : UInt32, # DWORD
pptlib : Void* # ITypeLib** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LoadRegTypeLibNative = Int32 Function(Pointer<Void>, Uint16, Uint16, Uint32, Pointer<Void>);
typedef LoadRegTypeLibDart = int Function(Pointer<Void>, int, int, int, Pointer<Void>);
final LoadRegTypeLib = DynamicLibrary.open('OLEAUT32.dll')
.lookupFunction<LoadRegTypeLibNative, LoadRegTypeLibDart>('LoadRegTypeLib');
// rguid : GUID* -> Pointer<Void>
// wVerMajor : WORD -> Uint16
// wVerMinor : WORD -> Uint16
// lcid : DWORD -> Uint32
// pptlib : ITypeLib** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LoadRegTypeLib(
rguid: PGUID; // GUID*
wVerMajor: Word; // WORD
wVerMinor: Word; // WORD
lcid: DWORD; // DWORD
pptlib: Pointer // ITypeLib** out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'LoadRegTypeLib';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LoadRegTypeLib"
c_LoadRegTypeLib :: Ptr () -> Word16 -> Word16 -> Word32 -> Ptr () -> IO Int32
-- rguid : GUID* -> Ptr ()
-- wVerMajor : WORD -> Word16
-- wVerMinor : WORD -> Word16
-- lcid : DWORD -> Word32
-- pptlib : ITypeLib** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let loadregtypelib =
foreign "LoadRegTypeLib"
((ptr void) @-> uint16_t @-> uint16_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* rguid : GUID* -> (ptr void) *)
(* wVerMajor : WORD -> uint16_t *)
(* wVerMinor : WORD -> uint16_t *)
(* lcid : DWORD -> uint32_t *)
(* pptlib : ITypeLib** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)
(cffi:defcfun ("LoadRegTypeLib" load-reg-type-lib :convention :stdcall) :int32
(rguid :pointer) ; GUID*
(w-ver-major :uint16) ; WORD
(w-ver-minor :uint16) ; WORD
(lcid :uint32) ; DWORD
(pptlib :pointer)) ; ITypeLib** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LoadRegTypeLib = Win32::API::More->new('OLEAUT32',
'int LoadRegTypeLib(LPVOID rguid, WORD wVerMajor, WORD wVerMinor, DWORD lcid, LPVOID pptlib)');
# my $ret = $LoadRegTypeLib->Call($rguid, $wVerMajor, $wVerMinor, $lcid, $pptlib);
# rguid : GUID* -> LPVOID
# wVerMajor : WORD -> WORD
# wVerMinor : WORD -> WORD
# lcid : DWORD -> DWORD
# pptlib : ITypeLib** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型