ホーム › System.Ole › OaEnablePerUserTLibRegistration
OaEnablePerUserTLibRegistration
関数ユーザー単位のタイプライブラリ登録を有効にする。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
void OaEnablePerUserTLibRegistration(void);パラメーターなし。戻り値: void
公式ドキュメント
Windows Vista Service Pack 1 (SP1)、Windows Server 2008、およびそれ以降のオペレーティング システムにおいて、RegisterTypeLib 関数が既定のレジストリ マッピングをオーバーライドできるようにします。
解説(Remarks)
次のシナリオを考えてみます。Windows Vista SP1 以降が動作しているコンピューターでアプリケーションを実行しています。このアプリケーションでは、HKEY_CLASSES_ROOT レジストリ サブツリーをオーバーライドし、別のレジストリ サブツリーにマッピングしています。(たとえば、HKEY_CLASSES_ROOT を HKEY_CURRENT_USER にマッピングしている場合などです。) その状態で RegisterTypeLib を呼び出してタイプ ライブラリを登録しようとすると、"アクセスが拒否されました" というエラー メッセージが表示されます。さらに、RegisterTypeLib は TYPE_E_REGISTRYACCESS (0x8002801c) の値を返します。
この問題は、ユーザー アカウント制御 (UAC) が有効で、かつアプリケーションが制限付きユーザー アカウントで実行されている場合に発生します。
この問題は、次の 2 つの方法のいずれかで解決できます。
- OaEnablePerUserTLibRegistration 関数を使用します。アプリケーションが RegisterTypeLib を呼び出す前に、OaEnablePerUserTLibRegistration を呼び出す必要があります。これにより、RegisterTypeLib はレジストリ オーバーライド マッピングを受け入れられるようになります。OaEnablePerUserTLibRegistration 関数は Oleaut32.dll ファイルからエクスポートされています。このファイルは、実行時の動的リンクと GetProcAddress 関数を使用して参照する必要があります。
-
OAPERUSERTLIBREG 環境変数を設定します。RegisterTypeLib はこの変数の値をチェックします。OAPERUSERTLIBREG の値が 1 の場合、RegisterTypeLib は適切なオーバーライド マッピングを使用します。この環境変数は DLLMain 関数の初期化中に読み取られるため、アプリケーションを実行する前に変数を設定しておく必要があります。設定するには、コマンド プロンプトで次のいずれかのコマンドを実行します。
set OAPERUSERTLIBREG=1
- または -
start cmd.exe /c "set OAPERUSERTLIBREG=1 && MyApp.exe"
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
void OaEnablePerUserTLibRegistration(void);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern void OaEnablePerUserTLibRegistration();<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Sub OaEnablePerUserTLibRegistration()
End SubDeclare PtrSafe Sub OaEnablePerUserTLibRegistration Lib "oleaut32" ()
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OaEnablePerUserTLibRegistration = ctypes.windll.oleaut32.OaEnablePerUserTLibRegistration
OaEnablePerUserTLibRegistration.restype = None
OaEnablePerUserTLibRegistration.argtypes = []require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
OaEnablePerUserTLibRegistration = Fiddle::Function.new(
lib['OaEnablePerUserTLibRegistration'],
[],
Fiddle::TYPE_VOID)#[link(name = "oleaut32")]
extern "system" {
fn OaEnablePerUserTLibRegistration();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern void OaEnablePerUserTLibRegistration();
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_OaEnablePerUserTLibRegistration' -Namespace Win32 -PassThru
# $api::OaEnablePerUserTLibRegistration()#uselib "OLEAUT32.dll"
#func global OaEnablePerUserTLibRegistration "OaEnablePerUserTLibRegistration"
; OaEnablePerUserTLibRegistration#uselib "OLEAUT32.dll"
#func global OaEnablePerUserTLibRegistration "OaEnablePerUserTLibRegistration"
; OaEnablePerUserTLibRegistration; void OaEnablePerUserTLibRegistration()
#uselib "OLEAUT32.dll"
#func global OaEnablePerUserTLibRegistration "OaEnablePerUserTLibRegistration"
; OaEnablePerUserTLibRegistrationimport (
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procOaEnablePerUserTLibRegistration = oleaut32.NewProc("OaEnablePerUserTLibRegistration")
)
r1, _, err := procOaEnablePerUserTLibRegistration.Call()
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure OaEnablePerUserTLibRegistration; stdcall;
external 'OLEAUT32.dll' name 'OaEnablePerUserTLibRegistration';result := DllCall("OLEAUT32\OaEnablePerUserTLibRegistration", "Int")●OaEnablePerUserTLibRegistration() = DLL("OLEAUT32.dll", "int OaEnablePerUserTLibRegistration()")
# 呼び出し: OaEnablePerUserTLibRegistration()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "oleaut32" fn OaEnablePerUserTLibRegistration() callconv(std.os.windows.WINAPI) void;proc OaEnablePerUserTLibRegistration() {.importc: "OaEnablePerUserTLibRegistration", stdcall, dynlib: "OLEAUT32.dll".}pragma(lib, "oleaut32");
extern(Windows)
void OaEnablePerUserTLibRegistration();ccall((:OaEnablePerUserTLibRegistration, "OLEAUT32.dll"), stdcall, Cvoid,
(),
)
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void OaEnablePerUserTLibRegistration(void);
]]
local oleaut32 = ffi.load("oleaut32")
-- oleaut32.OaEnablePerUserTLibRegistration()
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLEAUT32.dll');
const OaEnablePerUserTLibRegistration = lib.func('__stdcall', 'OaEnablePerUserTLibRegistration', 'void', []);
// OaEnablePerUserTLibRegistration()
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLEAUT32.dll", {
OaEnablePerUserTLibRegistration: { parameters: [], result: "void" },
});
// lib.symbols.OaEnablePerUserTLibRegistration()
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void OaEnablePerUserTLibRegistration(void);
C, "OLEAUT32.dll");
// $ffi->OaEnablePerUserTLibRegistration();
// 構造体/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);
void OaEnablePerUserTLibRegistration();
}@[Link("oleaut32")]
lib LibOLEAUT32
fun OaEnablePerUserTLibRegistration = OaEnablePerUserTLibRegistration() : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OaEnablePerUserTLibRegistrationNative = Void Function();
typedef OaEnablePerUserTLibRegistrationDart = void Function();
final OaEnablePerUserTLibRegistration = DynamicLibrary.open('OLEAUT32.dll')
.lookupFunction<OaEnablePerUserTLibRegistrationNative, OaEnablePerUserTLibRegistrationDart>('OaEnablePerUserTLibRegistration');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure OaEnablePerUserTLibRegistration; stdcall;
external 'OLEAUT32.dll' name 'OaEnablePerUserTLibRegistration';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OaEnablePerUserTLibRegistration"
c_OaEnablePerUserTLibRegistration :: IO ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let oaenableperusertlibregistration =
foreign "OaEnablePerUserTLibRegistration"
(void @-> returning void)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)
(cffi:defcfun ("OaEnablePerUserTLibRegistration" oa-enable-per-user-tlib-registration :convention :stdcall) :void)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OaEnablePerUserTLibRegistration = Win32::API::More->new('OLEAUT32',
'void OaEnablePerUserTLibRegistration()');
# my $ret = $OaEnablePerUserTLibRegistration->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。