ホーム › System.Com › CoRegisterDeviceCatalog
CoRegisterDeviceCatalog
関数デバイス用のCOMカタログを登録する。
シグネチャ
// OLE32.dll
#include <windows.h>
HRESULT CoRegisterDeviceCatalog(
LPCWSTR deviceInstanceId,
CO_DEVICE_CATALOG_COOKIE* cookie
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| deviceInstanceId | LPCWSTR | in | 登録するデバイスのインスタンス識別子を含む、null 終端文字列です。 |
| cookie | CO_DEVICE_CATALOG_COOKIE* | out | CO_DEVICE_CATALOG_COOKIE のインスタンスを返します。この値は、CoRevokeDeviceCatalog を使用してデバイスカタログを取り消す際に使用できます。 |
戻り値の型: HRESULT
公式ドキュメント
ダウンロードされた DLL が、実行中のプロセス内でデバイスカタログインターフェイスを登録できるようにし、マーシャリングコードがそれらのインターフェイスをマーシャリングできるようにします。
戻り値
この関数は、標準の戻り値である E_INVALIDARG、E_OUTOFMEMORY、および S_OK を返すことがあります。
解説(Remarks)
例
std::vector<CO_DEVICE_CATALOG_COOKIE> g_deviceCatalogsCookies;
HRESULT MFStartup(ULONG Version, DWORD dwFlags)
{
// current MFStartup code elided.
std::wstring devices{ /* set of device IDs of interest */ };
for (const auto& device : devices)
{
CO_DEVICE_CATALOG_COOKIE cookie{};
RETURN_IF_FAILED(CoRegisterDeviceCatalog(device.c_str(), &cookie));
g_deviceCatalogsCookies.push_back(cookie);
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE MFShutdown()
{
// current MFShutdown code elided
for (auto catalogCookie : g_deviceCatalogsCookies)
{
CoRevokeDeviceCatalog(catalogCookie);
}
return S_OK;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLE32.dll
#include <windows.h>
HRESULT CoRegisterDeviceCatalog(
LPCWSTR deviceInstanceId,
CO_DEVICE_CATALOG_COOKIE* cookie
);[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoRegisterDeviceCatalog(
[MarshalAs(UnmanagedType.LPWStr)] string deviceInstanceId, // LPCWSTR
IntPtr cookie // CO_DEVICE_CATALOG_COOKIE* out
);<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoRegisterDeviceCatalog(
<MarshalAs(UnmanagedType.LPWStr)> deviceInstanceId As String, ' LPCWSTR
cookie As IntPtr ' CO_DEVICE_CATALOG_COOKIE* out
) As Integer
End Function' deviceInstanceId : LPCWSTR
' cookie : CO_DEVICE_CATALOG_COOKIE* out
Declare PtrSafe Function CoRegisterDeviceCatalog Lib "ole32" ( _
ByVal deviceInstanceId As LongPtr, _
ByVal cookie As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CoRegisterDeviceCatalog = ctypes.windll.ole32.CoRegisterDeviceCatalog
CoRegisterDeviceCatalog.restype = ctypes.c_int
CoRegisterDeviceCatalog.argtypes = [
wintypes.LPCWSTR, # deviceInstanceId : LPCWSTR
ctypes.c_void_p, # cookie : CO_DEVICE_CATALOG_COOKIE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLE32.dll')
CoRegisterDeviceCatalog = Fiddle::Function.new(
lib['CoRegisterDeviceCatalog'],
[
Fiddle::TYPE_VOIDP, # deviceInstanceId : LPCWSTR
Fiddle::TYPE_VOIDP, # cookie : CO_DEVICE_CATALOG_COOKIE* out
],
Fiddle::TYPE_INT)#[link(name = "ole32")]
extern "system" {
fn CoRegisterDeviceCatalog(
deviceInstanceId: *const u16, // LPCWSTR
cookie: *mut *mut core::ffi::c_void // CO_DEVICE_CATALOG_COOKIE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoRegisterDeviceCatalog([MarshalAs(UnmanagedType.LPWStr)] string deviceInstanceId, IntPtr cookie);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoRegisterDeviceCatalog' -Namespace Win32 -PassThru
# $api::CoRegisterDeviceCatalog(deviceInstanceId, cookie)#uselib "OLE32.dll"
#func global CoRegisterDeviceCatalog "CoRegisterDeviceCatalog" sptr, sptr
; CoRegisterDeviceCatalog deviceInstanceId, cookie ; 戻り値は stat
; deviceInstanceId : LPCWSTR -> "sptr"
; cookie : CO_DEVICE_CATALOG_COOKIE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "OLE32.dll"
#cfunc global CoRegisterDeviceCatalog "CoRegisterDeviceCatalog" wstr, sptr
; res = CoRegisterDeviceCatalog(deviceInstanceId, cookie)
; deviceInstanceId : LPCWSTR -> "wstr"
; cookie : CO_DEVICE_CATALOG_COOKIE* out -> "sptr"; HRESULT CoRegisterDeviceCatalog(LPCWSTR deviceInstanceId, CO_DEVICE_CATALOG_COOKIE* cookie)
#uselib "OLE32.dll"
#cfunc global CoRegisterDeviceCatalog "CoRegisterDeviceCatalog" wstr, intptr
; res = CoRegisterDeviceCatalog(deviceInstanceId, cookie)
; deviceInstanceId : LPCWSTR -> "wstr"
; cookie : CO_DEVICE_CATALOG_COOKIE* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ole32 = windows.NewLazySystemDLL("OLE32.dll")
procCoRegisterDeviceCatalog = ole32.NewProc("CoRegisterDeviceCatalog")
)
// deviceInstanceId (LPCWSTR), cookie (CO_DEVICE_CATALOG_COOKIE* out)
r1, _, err := procCoRegisterDeviceCatalog.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(deviceInstanceId))),
uintptr(cookie),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CoRegisterDeviceCatalog(
deviceInstanceId: PWideChar; // LPCWSTR
cookie: Pointer // CO_DEVICE_CATALOG_COOKIE* out
): Integer; stdcall;
external 'OLE32.dll' name 'CoRegisterDeviceCatalog';result := DllCall("OLE32\CoRegisterDeviceCatalog"
, "WStr", deviceInstanceId ; LPCWSTR
, "Ptr", cookie ; CO_DEVICE_CATALOG_COOKIE* out
, "Int") ; return: HRESULT●CoRegisterDeviceCatalog(deviceInstanceId, cookie) = DLL("OLE32.dll", "int CoRegisterDeviceCatalog(char*, void*)")
# 呼び出し: CoRegisterDeviceCatalog(deviceInstanceId, cookie)
# deviceInstanceId : LPCWSTR -> "char*"
# cookie : CO_DEVICE_CATALOG_COOKIE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ole32" fn CoRegisterDeviceCatalog(
deviceInstanceId: [*c]const u16, // LPCWSTR
cookie: ?*anyopaque // CO_DEVICE_CATALOG_COOKIE* out
) callconv(std.os.windows.WINAPI) i32;proc CoRegisterDeviceCatalog(
deviceInstanceId: WideCString, # LPCWSTR
cookie: pointer # CO_DEVICE_CATALOG_COOKIE* out
): int32 {.importc: "CoRegisterDeviceCatalog", stdcall, dynlib: "OLE32.dll".}pragma(lib, "ole32");
extern(Windows)
int CoRegisterDeviceCatalog(
const(wchar)* deviceInstanceId, // LPCWSTR
void* cookie // CO_DEVICE_CATALOG_COOKIE* out
);ccall((:CoRegisterDeviceCatalog, "OLE32.dll"), stdcall, Int32,
(Cwstring, Ptr{Cvoid}),
deviceInstanceId, cookie)
# deviceInstanceId : LPCWSTR -> Cwstring
# cookie : CO_DEVICE_CATALOG_COOKIE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CoRegisterDeviceCatalog(
const uint16_t* deviceInstanceId,
void* cookie);
]]
local ole32 = ffi.load("ole32")
-- ole32.CoRegisterDeviceCatalog(deviceInstanceId, cookie)
-- deviceInstanceId : LPCWSTR
-- cookie : CO_DEVICE_CATALOG_COOKIE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const CoRegisterDeviceCatalog = lib.func('__stdcall', 'CoRegisterDeviceCatalog', 'int32_t', ['str16', 'void *']);
// CoRegisterDeviceCatalog(deviceInstanceId, cookie)
// deviceInstanceId : LPCWSTR -> 'str16'
// cookie : CO_DEVICE_CATALOG_COOKIE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLE32.dll", {
CoRegisterDeviceCatalog: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.CoRegisterDeviceCatalog(deviceInstanceId, cookie)
// deviceInstanceId : LPCWSTR -> "buffer"
// cookie : CO_DEVICE_CATALOG_COOKIE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CoRegisterDeviceCatalog(
const uint16_t* deviceInstanceId,
void* cookie);
C, "OLE32.dll");
// $ffi->CoRegisterDeviceCatalog(deviceInstanceId, cookie);
// deviceInstanceId : LPCWSTR
// cookie : CO_DEVICE_CATALOG_COOKIE* 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 CoRegisterDeviceCatalog(
WString deviceInstanceId, // LPCWSTR
Pointer cookie // CO_DEVICE_CATALOG_COOKIE* out
);
}@[Link("ole32")]
lib LibOLE32
fun CoRegisterDeviceCatalog = CoRegisterDeviceCatalog(
deviceInstanceId : UInt16*, # LPCWSTR
cookie : Void* # CO_DEVICE_CATALOG_COOKIE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CoRegisterDeviceCatalogNative = Int32 Function(Pointer<Utf16>, Pointer<Void>);
typedef CoRegisterDeviceCatalogDart = int Function(Pointer<Utf16>, Pointer<Void>);
final CoRegisterDeviceCatalog = DynamicLibrary.open('OLE32.dll')
.lookupFunction<CoRegisterDeviceCatalogNative, CoRegisterDeviceCatalogDart>('CoRegisterDeviceCatalog');
// deviceInstanceId : LPCWSTR -> Pointer<Utf16>
// cookie : CO_DEVICE_CATALOG_COOKIE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CoRegisterDeviceCatalog(
deviceInstanceId: PWideChar; // LPCWSTR
cookie: Pointer // CO_DEVICE_CATALOG_COOKIE* out
): Integer; stdcall;
external 'OLE32.dll' name 'CoRegisterDeviceCatalog';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CoRegisterDeviceCatalog"
c_CoRegisterDeviceCatalog :: CWString -> Ptr () -> IO Int32
-- deviceInstanceId : LPCWSTR -> CWString
-- cookie : CO_DEVICE_CATALOG_COOKIE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let coregisterdevicecatalog =
foreign "CoRegisterDeviceCatalog"
((ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* deviceInstanceId : LPCWSTR -> (ptr uint16_t) *)
(* cookie : CO_DEVICE_CATALOG_COOKIE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)
(cffi:defcfun ("CoRegisterDeviceCatalog" co-register-device-catalog :convention :stdcall) :int32
(device-instance-id (:string :encoding :utf-16le)) ; LPCWSTR
(cookie :pointer)) ; CO_DEVICE_CATALOG_COOKIE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CoRegisterDeviceCatalog = Win32::API::More->new('OLE32',
'int CoRegisterDeviceCatalog(LPCWSTR deviceInstanceId, HANDLE cookie)');
# my $ret = $CoRegisterDeviceCatalog->Call($deviceInstanceId, $cookie);
# deviceInstanceId : LPCWSTR -> LPCWSTR
# cookie : CO_DEVICE_CATALOG_COOKIE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。