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

OleRegGetUserType

関数
レジストリからCLSIDのユーザー表示用タイプ名を取得する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT OleRegGetUserType(
    const GUID* clsid,
    DWORD dwFormOfType,
    LPWSTR* pszUserType
);

パラメーター

名前方向説明
clsidGUID*inユーザータイプを取得する対象クラスの CLSID。
dwFormOfTypeDWORDinユーザーに提示する文字列の形式。指定可能な値は列挙型 USERCLASSTYPE から取得します。
pszUserTypeLPWSTR*outユーザータイプを受け取る文字列へのポインター。

戻り値の型: HRESULT

公式ドキュメント

指定したクラスのユーザータイプをレジストリから取得します。

戻り値

この関数は、標準の戻り値 E_OUTOFMEMORY のほか、次の値を返すことがあります。

戻り値 説明
S_OK
ユーザータイプが正常に返されました。
REGDB_E_CLASSNOTREG
クラスオブジェクトに対して CLSID が登録されていません。
REGDB_E_READREGDB
レジストリの読み取り中にエラーが発生しました。
OLE_E_REGDB_KEY
ProgID = MainUserTypeName キーおよび CLSID = MainUserTypeName キーがレジストリに存在しません。

解説(Remarks)

オブジェクトアプリケーションは、指定したクラスのユーザータイプ名を取得するよう OLE に依頼するために、2 通りの方法を使用できます。1 つは OleRegGetUserType を呼び出す方法です。もう 1 つは、既定のオブジェクトハンドラーによる IOleObject::GetUserType の呼び出しに応答して OLE_S_USEREG を返す方法です。OLE_S_USEREG は、既定のハンドラーに OleRegGetUserType を呼び出すよう指示します。DLL オブジェクトアプリケーションは OLE_S_USEREG を返せないため、処理をオブジェクトハンドラーに委ねるのではなく、OleRegGetUserType を直接呼び出す必要があります。

OleRegGetUserType 関数と、その関連関数である OleRegGetMiscStatusOleRegEnumFormatEtcOleRegEnumVerbs は、カスタム DLL オブジェクトアプリケーションの開発者が、レジストリからオブジェクトに関する情報を取得する際の OLE 既定オブジェクトハンドラーの動作をエミュレートする手段を提供します。これらの関数を使用することで、独自に実装する多大な労力や、レジストリを直接操作する際に伴う落とし穴を回避できます。さらに、これらの関数に対する将来の機能拡張や最適化を、自分でコーディングすることなく利用できます。

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

各言語での呼び出し定義

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

HRESULT OleRegGetUserType(
    const GUID* clsid,
    DWORD dwFormOfType,
    LPWSTR* pszUserType
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int OleRegGetUserType(
    ref Guid clsid,   // GUID*
    uint dwFormOfType,   // DWORD
    IntPtr pszUserType   // LPWSTR* out
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function OleRegGetUserType(
    ByRef clsid As Guid,   ' GUID*
    dwFormOfType As UInteger,   ' DWORD
    pszUserType As IntPtr   ' LPWSTR* out
) As Integer
End Function
' clsid : GUID*
' dwFormOfType : DWORD
' pszUserType : LPWSTR* out
Declare PtrSafe Function OleRegGetUserType Lib "ole32" ( _
    ByVal clsid As LongPtr, _
    ByVal dwFormOfType As Long, _
    ByVal pszUserType As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

OleRegGetUserType = ctypes.windll.ole32.OleRegGetUserType
OleRegGetUserType.restype = ctypes.c_int
OleRegGetUserType.argtypes = [
    ctypes.c_void_p,  # clsid : GUID*
    wintypes.DWORD,  # dwFormOfType : DWORD
    ctypes.c_void_p,  # pszUserType : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
OleRegGetUserType = Fiddle::Function.new(
  lib['OleRegGetUserType'],
  [
    Fiddle::TYPE_VOIDP,  # clsid : GUID*
    -Fiddle::TYPE_INT,  # dwFormOfType : DWORD
    Fiddle::TYPE_VOIDP,  # pszUserType : LPWSTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn OleRegGetUserType(
        clsid: *const GUID,  // GUID*
        dwFormOfType: u32,  // DWORD
        pszUserType: *mut *mut u16  // LPWSTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int OleRegGetUserType(ref Guid clsid, uint dwFormOfType, IntPtr pszUserType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_OleRegGetUserType' -Namespace Win32 -PassThru
# $api::OleRegGetUserType(clsid, dwFormOfType, pszUserType)
#uselib "OLE32.dll"
#func global OleRegGetUserType "OleRegGetUserType" sptr, sptr, sptr
; OleRegGetUserType varptr(clsid), dwFormOfType, varptr(pszUserType)   ; 戻り値は stat
; clsid : GUID* -> "sptr"
; dwFormOfType : DWORD -> "sptr"
; pszUserType : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLE32.dll"
#cfunc global OleRegGetUserType "OleRegGetUserType" var, int, var
; res = OleRegGetUserType(clsid, dwFormOfType, pszUserType)
; clsid : GUID* -> "var"
; dwFormOfType : DWORD -> "int"
; pszUserType : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT OleRegGetUserType(GUID* clsid, DWORD dwFormOfType, LPWSTR* pszUserType)
#uselib "OLE32.dll"
#cfunc global OleRegGetUserType "OleRegGetUserType" var, int, var
; res = OleRegGetUserType(clsid, dwFormOfType, pszUserType)
; clsid : GUID* -> "var"
; dwFormOfType : DWORD -> "int"
; pszUserType : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procOleRegGetUserType = ole32.NewProc("OleRegGetUserType")
)

// clsid (GUID*), dwFormOfType (DWORD), pszUserType (LPWSTR* out)
r1, _, err := procOleRegGetUserType.Call(
	uintptr(clsid),
	uintptr(dwFormOfType),
	uintptr(pszUserType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function OleRegGetUserType(
  clsid: PGUID;   // GUID*
  dwFormOfType: DWORD;   // DWORD
  pszUserType: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'OLE32.dll' name 'OleRegGetUserType';
result := DllCall("OLE32\OleRegGetUserType"
    , "Ptr", clsid   ; GUID*
    , "UInt", dwFormOfType   ; DWORD
    , "Ptr", pszUserType   ; LPWSTR* out
    , "Int")   ; return: HRESULT
●OleRegGetUserType(clsid, dwFormOfType, pszUserType) = DLL("OLE32.dll", "int OleRegGetUserType(void*, dword, void*)")
# 呼び出し: OleRegGetUserType(clsid, dwFormOfType, pszUserType)
# clsid : GUID* -> "void*"
# dwFormOfType : DWORD -> "dword"
# pszUserType : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef OleRegGetUserTypeNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Pointer<Utf16>>);
typedef OleRegGetUserTypeDart = int Function(Pointer<Void>, int, Pointer<Pointer<Utf16>>);
final OleRegGetUserType = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<OleRegGetUserTypeNative, OleRegGetUserTypeDart>('OleRegGetUserType');
// clsid : GUID* -> Pointer<Void>
// dwFormOfType : DWORD -> Uint32
// pszUserType : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function OleRegGetUserType(
  clsid: PGUID;   // GUID*
  dwFormOfType: DWORD;   // DWORD
  pszUserType: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'OLE32.dll' name 'OleRegGetUserType';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "OleRegGetUserType"
  c_OleRegGetUserType :: Ptr () -> Word32 -> Ptr CWString -> IO Int32
-- clsid : GUID* -> Ptr ()
-- dwFormOfType : DWORD -> Word32
-- pszUserType : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let olereggetusertype =
  foreign "OleRegGetUserType"
    ((ptr void) @-> uint32_t @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* clsid : GUID* -> (ptr void) *)
(* dwFormOfType : DWORD -> uint32_t *)
(* pszUserType : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("OleRegGetUserType" ole-reg-get-user-type :convention :stdcall) :int32
  (clsid :pointer)   ; GUID*
  (dw-form-of-type :uint32)   ; DWORD
  (psz-user-type :pointer))   ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $OleRegGetUserType = Win32::API::More->new('OLE32',
    'int OleRegGetUserType(LPVOID clsid, DWORD dwFormOfType, LPVOID pszUserType)');
# my $ret = $OleRegGetUserType->Call($clsid, $dwFormOfType, $pszUserType);
# clsid : GUID* -> LPVOID
# dwFormOfType : DWORD -> DWORD
# pszUserType : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目