Win32 API 日本語リファレンス
ホームNetworkManagement.P2P › DrtRegisterKey

DrtRegisterKey

関数
DRTにキーを登録して公開する。
DLLdrt.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT DrtRegisterKey(
    void* hDrt,
    DRT_REGISTRATION* pRegistration,
    void* pvKeyContext,   // optional
    void** phKeyRegistration
);

パラメーター

名前方向説明
hDrtvoid*in登録先のDRTインスタンスのハンドル。
pRegistrationDRT_REGISTRATION*in登録するキーと付随データを格納したDRT_REGISTRATION構造体へのポインタ。
pvKeyContextvoid*inoptionalキーに関連付ける呼び出し側コンテキスト。NULL可。
phKeyRegistrationvoid**outキー登録ハンドルを受け取るポインタ。更新や解除に使う。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DrtRegisterKey(
    void* hDrt,
    DRT_REGISTRATION* pRegistration,
    void* pvKeyContext,   // optional
    void** phKeyRegistration
);
[DllImport("drt.dll", ExactSpelling = true)]
static extern int DrtRegisterKey(
    IntPtr hDrt,   // void*
    IntPtr pRegistration,   // DRT_REGISTRATION*
    IntPtr pvKeyContext,   // void* optional
    IntPtr phKeyRegistration   // void** out
);
<DllImport("drt.dll", ExactSpelling:=True)>
Public Shared Function DrtRegisterKey(
    hDrt As IntPtr,   ' void*
    pRegistration As IntPtr,   ' DRT_REGISTRATION*
    pvKeyContext As IntPtr,   ' void* optional
    phKeyRegistration As IntPtr   ' void** out
) As Integer
End Function
' hDrt : void*
' pRegistration : DRT_REGISTRATION*
' pvKeyContext : void* optional
' phKeyRegistration : void** out
Declare PtrSafe Function DrtRegisterKey Lib "drt" ( _
    ByVal hDrt As LongPtr, _
    ByVal pRegistration As LongPtr, _
    ByVal pvKeyContext As LongPtr, _
    ByVal phKeyRegistration As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrtRegisterKey = ctypes.windll.drt.DrtRegisterKey
DrtRegisterKey.restype = ctypes.c_int
DrtRegisterKey.argtypes = [
    ctypes.POINTER(None),  # hDrt : void*
    ctypes.c_void_p,  # pRegistration : DRT_REGISTRATION*
    ctypes.POINTER(None),  # pvKeyContext : void* optional
    ctypes.c_void_p,  # phKeyRegistration : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	drt = windows.NewLazySystemDLL("drt.dll")
	procDrtRegisterKey = drt.NewProc("DrtRegisterKey")
)

// hDrt (void*), pRegistration (DRT_REGISTRATION*), pvKeyContext (void* optional), phKeyRegistration (void** out)
r1, _, err := procDrtRegisterKey.Call(
	uintptr(hDrt),
	uintptr(pRegistration),
	uintptr(pvKeyContext),
	uintptr(phKeyRegistration),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DrtRegisterKey(
  hDrt: Pointer;   // void*
  pRegistration: Pointer;   // DRT_REGISTRATION*
  pvKeyContext: Pointer;   // void* optional
  phKeyRegistration: Pointer   // void** out
): Integer; stdcall;
  external 'drt.dll' name 'DrtRegisterKey';
result := DllCall("drt\DrtRegisterKey"
    , "Ptr", hDrt   ; void*
    , "Ptr", pRegistration   ; DRT_REGISTRATION*
    , "Ptr", pvKeyContext   ; void* optional
    , "Ptr", phKeyRegistration   ; void** out
    , "Int")   ; return: HRESULT
●DrtRegisterKey(hDrt, pRegistration, pvKeyContext, phKeyRegistration) = DLL("drt.dll", "int DrtRegisterKey(void*, void*, void*, void*)")
# 呼び出し: DrtRegisterKey(hDrt, pRegistration, pvKeyContext, phKeyRegistration)
# hDrt : void* -> "void*"
# pRegistration : DRT_REGISTRATION* -> "void*"
# pvKeyContext : void* optional -> "void*"
# phKeyRegistration : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DrtRegisterKeyNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef DrtRegisterKeyDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final DrtRegisterKey = DynamicLibrary.open('drt.dll')
    .lookupFunction<DrtRegisterKeyNative, DrtRegisterKeyDart>('DrtRegisterKey');
// hDrt : void* -> Pointer<Void>
// pRegistration : DRT_REGISTRATION* -> Pointer<Void>
// pvKeyContext : void* optional -> Pointer<Void>
// phKeyRegistration : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DrtRegisterKey(
  hDrt: Pointer;   // void*
  pRegistration: Pointer;   // DRT_REGISTRATION*
  pvKeyContext: Pointer;   // void* optional
  phKeyRegistration: Pointer   // void** out
): Integer; stdcall;
  external 'drt.dll' name 'DrtRegisterKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DrtRegisterKey"
  c_DrtRegisterKey :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hDrt : void* -> Ptr ()
-- pRegistration : DRT_REGISTRATION* -> Ptr ()
-- pvKeyContext : void* optional -> Ptr ()
-- phKeyRegistration : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drtregisterkey =
  foreign "DrtRegisterKey"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hDrt : void* -> (ptr void) *)
(* pRegistration : DRT_REGISTRATION* -> (ptr void) *)
(* pvKeyContext : void* optional -> (ptr void) *)
(* phKeyRegistration : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library drt (t "drt.dll"))
(cffi:use-foreign-library drt)

(cffi:defcfun ("DrtRegisterKey" drt-register-key :convention :stdcall) :int32
  (h-drt :pointer)   ; void*
  (p-registration :pointer)   ; DRT_REGISTRATION*
  (pv-key-context :pointer)   ; void* optional
  (ph-key-registration :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DrtRegisterKey = Win32::API::More->new('drt',
    'int DrtRegisterKey(LPVOID hDrt, LPVOID pRegistration, LPVOID pvKeyContext, LPVOID phKeyRegistration)');
# my $ret = $DrtRegisterKey->Call($hDrt, $pRegistration, $pvKeyContext, $phKeyRegistration);
# hDrt : void* -> LPVOID
# pRegistration : DRT_REGISTRATION* -> LPVOID
# pvKeyContext : void* optional -> LPVOID
# phKeyRegistration : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型