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

RegisterTypeLibForUser

関数
タイプライブラリを現在のユーザー単位でレジストリに登録する。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT RegisterTypeLibForUser(
    ITypeLib* ptlib,
    LPWSTR szFullPath,
    LPWSTR szHelpDir   // optional
);

パラメーター

名前方向説明
ptlibITypeLib*inタイプ ライブラリ。
szFullPathLPWSTRinタイプ ライブラリの完全修飾パス指定。
szHelpDirLPWSTRinoptional登録対象のライブラリのヘルプ ファイルが格納されているディレクトリ。このパラメーターは null にすることができます。

戻り値の型: HRESULT

公式ドキュメント

呼び出し元ユーザーが使用するためにタイプ ライブラリを登録します。

戻り値

この関数は次のいずれかの値を返すことができます。

戻り値 説明
S_OK
成功しました。
E_INVALIDARG
1 つ以上の引数が無効です。
E_OUTOFMEMORY
操作を完了するためのメモリが不足しています。
TYPE_E_IOERROR
関数がファイルに書き込めませんでした。
TYPE_E_REGISTRYACCESS
システム登録データベースを開けませんでした。
TYPE_E_INVALIDSTATE
タイプ ライブラリを開けませんでした。

解説(Remarks)

RegisterTypeLibForUserRegisterTypeLib と同一の機能を持ちますが、タイプ ライブラリが呼び出し元ユーザー ID によってのみ使用されるように登録される点が異なります。

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

各言語での呼び出し定義

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

HRESULT RegisterTypeLibForUser(
    ITypeLib* ptlib,
    LPWSTR szFullPath,
    LPWSTR szHelpDir   // optional
);
[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int RegisterTypeLibForUser(
    IntPtr ptlib,   // ITypeLib*
    [MarshalAs(UnmanagedType.LPWStr)] string szFullPath,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szHelpDir   // LPWSTR optional
);
<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function RegisterTypeLibForUser(
    ptlib As IntPtr,   ' ITypeLib*
    <MarshalAs(UnmanagedType.LPWStr)> szFullPath As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szHelpDir As String   ' LPWSTR optional
) As Integer
End Function
' ptlib : ITypeLib*
' szFullPath : LPWSTR
' szHelpDir : LPWSTR optional
Declare PtrSafe Function RegisterTypeLibForUser Lib "oleaut32" ( _
    ByVal ptlib As LongPtr, _
    ByVal szFullPath As LongPtr, _
    ByVal szHelpDir As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterTypeLibForUser = ctypes.windll.oleaut32.RegisterTypeLibForUser
RegisterTypeLibForUser.restype = ctypes.c_int
RegisterTypeLibForUser.argtypes = [
    ctypes.c_void_p,  # ptlib : ITypeLib*
    wintypes.LPCWSTR,  # szFullPath : LPWSTR
    wintypes.LPCWSTR,  # szHelpDir : LPWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLEAUT32.dll')
RegisterTypeLibForUser = Fiddle::Function.new(
  lib['RegisterTypeLibForUser'],
  [
    Fiddle::TYPE_VOIDP,  # ptlib : ITypeLib*
    Fiddle::TYPE_VOIDP,  # szFullPath : LPWSTR
    Fiddle::TYPE_VOIDP,  # szHelpDir : LPWSTR optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "oleaut32")]
extern "system" {
    fn RegisterTypeLibForUser(
        ptlib: *mut core::ffi::c_void,  // ITypeLib*
        szFullPath: *mut u16,  // LPWSTR
        szHelpDir: *mut u16  // LPWSTR optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int RegisterTypeLibForUser(IntPtr ptlib, [MarshalAs(UnmanagedType.LPWStr)] string szFullPath, [MarshalAs(UnmanagedType.LPWStr)] string szHelpDir);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_RegisterTypeLibForUser' -Namespace Win32 -PassThru
# $api::RegisterTypeLibForUser(ptlib, szFullPath, szHelpDir)
#uselib "OLEAUT32.dll"
#func global RegisterTypeLibForUser "RegisterTypeLibForUser" sptr, sptr, sptr
; RegisterTypeLibForUser ptlib, szFullPath, szHelpDir   ; 戻り値は stat
; ptlib : ITypeLib* -> "sptr"
; szFullPath : LPWSTR -> "sptr"
; szHelpDir : LPWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLEAUT32.dll"
#cfunc global RegisterTypeLibForUser "RegisterTypeLibForUser" sptr, wstr, wstr
; res = RegisterTypeLibForUser(ptlib, szFullPath, szHelpDir)
; ptlib : ITypeLib* -> "sptr"
; szFullPath : LPWSTR -> "wstr"
; szHelpDir : LPWSTR optional -> "wstr"
; HRESULT RegisterTypeLibForUser(ITypeLib* ptlib, LPWSTR szFullPath, LPWSTR szHelpDir)
#uselib "OLEAUT32.dll"
#cfunc global RegisterTypeLibForUser "RegisterTypeLibForUser" intptr, wstr, wstr
; res = RegisterTypeLibForUser(ptlib, szFullPath, szHelpDir)
; ptlib : ITypeLib* -> "intptr"
; szFullPath : LPWSTR -> "wstr"
; szHelpDir : LPWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procRegisterTypeLibForUser = oleaut32.NewProc("RegisterTypeLibForUser")
)

// ptlib (ITypeLib*), szFullPath (LPWSTR), szHelpDir (LPWSTR optional)
r1, _, err := procRegisterTypeLibForUser.Call(
	uintptr(ptlib),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFullPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szHelpDir))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function RegisterTypeLibForUser(
  ptlib: Pointer;   // ITypeLib*
  szFullPath: PWideChar;   // LPWSTR
  szHelpDir: PWideChar   // LPWSTR optional
): Integer; stdcall;
  external 'OLEAUT32.dll' name 'RegisterTypeLibForUser';
result := DllCall("OLEAUT32\RegisterTypeLibForUser"
    , "Ptr", ptlib   ; ITypeLib*
    , "WStr", szFullPath   ; LPWSTR
    , "WStr", szHelpDir   ; LPWSTR optional
    , "Int")   ; return: HRESULT
●RegisterTypeLibForUser(ptlib, szFullPath, szHelpDir) = DLL("OLEAUT32.dll", "int RegisterTypeLibForUser(void*, char*, char*)")
# 呼び出し: RegisterTypeLibForUser(ptlib, szFullPath, szHelpDir)
# ptlib : ITypeLib* -> "void*"
# szFullPath : LPWSTR -> "char*"
# szHelpDir : LPWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef RegisterTypeLibForUserNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>);
typedef RegisterTypeLibForUserDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>);
final RegisterTypeLibForUser = DynamicLibrary.open('OLEAUT32.dll')
    .lookupFunction<RegisterTypeLibForUserNative, RegisterTypeLibForUserDart>('RegisterTypeLibForUser');
// ptlib : ITypeLib* -> Pointer<Void>
// szFullPath : LPWSTR -> Pointer<Utf16>
// szHelpDir : LPWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterTypeLibForUser(
  ptlib: Pointer;   // ITypeLib*
  szFullPath: PWideChar;   // LPWSTR
  szHelpDir: PWideChar   // LPWSTR optional
): Integer; stdcall;
  external 'OLEAUT32.dll' name 'RegisterTypeLibForUser';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterTypeLibForUser"
  c_RegisterTypeLibForUser :: Ptr () -> CWString -> CWString -> IO Int32
-- ptlib : ITypeLib* -> Ptr ()
-- szFullPath : LPWSTR -> CWString
-- szHelpDir : LPWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let registertypelibforuser =
  foreign "RegisterTypeLibForUser"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* ptlib : ITypeLib* -> (ptr void) *)
(* szFullPath : LPWSTR -> (ptr uint16_t) *)
(* szHelpDir : LPWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)

(cffi:defcfun ("RegisterTypeLibForUser" register-type-lib-for-user :convention :stdcall) :int32
  (ptlib :pointer)   ; ITypeLib*
  (sz-full-path (:string :encoding :utf-16le))   ; LPWSTR
  (sz-help-dir (:string :encoding :utf-16le)))   ; LPWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterTypeLibForUser = Win32::API::More->new('OLEAUT32',
    'int RegisterTypeLibForUser(LPVOID ptlib, LPCWSTR szFullPath, LPCWSTR szHelpDir)');
# my $ret = $RegisterTypeLibForUser->Call($ptlib, $szFullPath, $szHelpDir);
# ptlib : ITypeLib* -> LPVOID
# szFullPath : LPWSTR -> LPCWSTR
# szHelpDir : LPWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型