Win32 API 日本語リファレンス
ホームNetworking.Clustering › ClusterRegOpenKey

ClusterRegOpenKey

関数
クラスターレジストリ内の既存サブキーを開く。
DLLCLUSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

INT ClusterRegOpenKey(
    HKEY hKey,
    LPCWSTR lpszSubKey,
    DWORD samDesired,
    HKEY* phkResult
);

パラメーター

名前方向説明
hKeyHKEYin開く位置の親となる開いているクラスターレジストリキー。
lpszSubKeyLPCWSTRin開くサブキーのパスを示すワイド文字列。
samDesiredDWORDin開くキーに要求するアクセス権を示すアクセスマスク。
phkResultHKEY*out開かれたキーのハンドルを受け取るポインタ。

戻り値の型: INT

各言語での呼び出し定義

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

INT ClusterRegOpenKey(
    HKEY hKey,
    LPCWSTR lpszSubKey,
    DWORD samDesired,
    HKEY* phkResult
);
[DllImport("CLUSAPI.dll", ExactSpelling = true)]
static extern int ClusterRegOpenKey(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey,   // LPCWSTR
    uint samDesired,   // DWORD
    IntPtr phkResult   // HKEY* out
);
<DllImport("CLUSAPI.dll", ExactSpelling:=True)>
Public Shared Function ClusterRegOpenKey(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpszSubKey As String,   ' LPCWSTR
    samDesired As UInteger,   ' DWORD
    phkResult As IntPtr   ' HKEY* out
) As Integer
End Function
' hKey : HKEY
' lpszSubKey : LPCWSTR
' samDesired : DWORD
' phkResult : HKEY* out
Declare PtrSafe Function ClusterRegOpenKey Lib "clusapi" ( _
    ByVal hKey As LongPtr, _
    ByVal lpszSubKey As LongPtr, _
    ByVal samDesired As Long, _
    ByVal phkResult As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ClusterRegOpenKey = ctypes.windll.clusapi.ClusterRegOpenKey
ClusterRegOpenKey.restype = ctypes.c_int
ClusterRegOpenKey.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpszSubKey : LPCWSTR
    wintypes.DWORD,  # samDesired : DWORD
    ctypes.c_void_p,  # phkResult : HKEY* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CLUSAPI.dll')
ClusterRegOpenKey = Fiddle::Function.new(
  lib['ClusterRegOpenKey'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # lpszSubKey : LPCWSTR
    -Fiddle::TYPE_INT,  # samDesired : DWORD
    Fiddle::TYPE_VOIDP,  # phkResult : HKEY* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "clusapi")]
extern "system" {
    fn ClusterRegOpenKey(
        hKey: *mut core::ffi::c_void,  // HKEY
        lpszSubKey: *const u16,  // LPCWSTR
        samDesired: u32,  // DWORD
        phkResult: *mut *mut core::ffi::c_void  // HKEY* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CLUSAPI.dll")]
public static extern int ClusterRegOpenKey(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey, uint samDesired, IntPtr phkResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CLUSAPI_ClusterRegOpenKey' -Namespace Win32 -PassThru
# $api::ClusterRegOpenKey(hKey, lpszSubKey, samDesired, phkResult)
#uselib "CLUSAPI.dll"
#func global ClusterRegOpenKey "ClusterRegOpenKey" sptr, sptr, sptr, sptr
; ClusterRegOpenKey hKey, lpszSubKey, samDesired, phkResult   ; 戻り値は stat
; hKey : HKEY -> "sptr"
; lpszSubKey : LPCWSTR -> "sptr"
; samDesired : DWORD -> "sptr"
; phkResult : HKEY* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegOpenKey "ClusterRegOpenKey" sptr, wstr, int, sptr
; res = ClusterRegOpenKey(hKey, lpszSubKey, samDesired, phkResult)
; hKey : HKEY -> "sptr"
; lpszSubKey : LPCWSTR -> "wstr"
; samDesired : DWORD -> "int"
; phkResult : HKEY* out -> "sptr"
; INT ClusterRegOpenKey(HKEY hKey, LPCWSTR lpszSubKey, DWORD samDesired, HKEY* phkResult)
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegOpenKey "ClusterRegOpenKey" intptr, wstr, int, intptr
; res = ClusterRegOpenKey(hKey, lpszSubKey, samDesired, phkResult)
; hKey : HKEY -> "intptr"
; lpszSubKey : LPCWSTR -> "wstr"
; samDesired : DWORD -> "int"
; phkResult : HKEY* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterRegOpenKey = clusapi.NewProc("ClusterRegOpenKey")
)

// hKey (HKEY), lpszSubKey (LPCWSTR), samDesired (DWORD), phkResult (HKEY* out)
r1, _, err := procClusterRegOpenKey.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszSubKey))),
	uintptr(samDesired),
	uintptr(phkResult),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function ClusterRegOpenKey(
  hKey: THandle;   // HKEY
  lpszSubKey: PWideChar;   // LPCWSTR
  samDesired: DWORD;   // DWORD
  phkResult: Pointer   // HKEY* out
): Integer; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegOpenKey';
result := DllCall("CLUSAPI\ClusterRegOpenKey"
    , "Ptr", hKey   ; HKEY
    , "WStr", lpszSubKey   ; LPCWSTR
    , "UInt", samDesired   ; DWORD
    , "Ptr", phkResult   ; HKEY* out
    , "Int")   ; return: INT
●ClusterRegOpenKey(hKey, lpszSubKey, samDesired, phkResult) = DLL("CLUSAPI.dll", "int ClusterRegOpenKey(void*, char*, dword, void*)")
# 呼び出し: ClusterRegOpenKey(hKey, lpszSubKey, samDesired, phkResult)
# hKey : HKEY -> "void*"
# lpszSubKey : LPCWSTR -> "char*"
# samDesired : DWORD -> "dword"
# phkResult : HKEY* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ClusterRegOpenKeyNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>);
typedef ClusterRegOpenKeyDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>);
final ClusterRegOpenKey = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<ClusterRegOpenKeyNative, ClusterRegOpenKeyDart>('ClusterRegOpenKey');
// hKey : HKEY -> Pointer<Void>
// lpszSubKey : LPCWSTR -> Pointer<Utf16>
// samDesired : DWORD -> Uint32
// phkResult : HKEY* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterRegOpenKey(
  hKey: THandle;   // HKEY
  lpszSubKey: PWideChar;   // LPCWSTR
  samDesired: DWORD;   // DWORD
  phkResult: Pointer   // HKEY* out
): Integer; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegOpenKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ClusterRegOpenKey"
  c_ClusterRegOpenKey :: Ptr () -> CWString -> Word32 -> Ptr () -> IO Int32
-- hKey : HKEY -> Ptr ()
-- lpszSubKey : LPCWSTR -> CWString
-- samDesired : DWORD -> Word32
-- phkResult : HKEY* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let clusterregopenkey =
  foreign "ClusterRegOpenKey"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hKey : HKEY -> (ptr void) *)
(* lpszSubKey : LPCWSTR -> (ptr uint16_t) *)
(* samDesired : DWORD -> uint32_t *)
(* phkResult : HKEY* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("ClusterRegOpenKey" cluster-reg-open-key :convention :stdcall) :int32
  (h-key :pointer)   ; HKEY
  (lpsz-sub-key (:string :encoding :utf-16le))   ; LPCWSTR
  (sam-desired :uint32)   ; DWORD
  (phk-result :pointer))   ; HKEY* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterRegOpenKey = Win32::API::More->new('CLUSAPI',
    'int ClusterRegOpenKey(HANDLE hKey, LPCWSTR lpszSubKey, DWORD samDesired, HANDLE phkResult)');
# my $ret = $ClusterRegOpenKey->Call($hKey, $lpszSubKey, $samDesired, $phkResult);
# hKey : HKEY -> HANDLE
# lpszSubKey : LPCWSTR -> LPCWSTR
# samDesired : DWORD -> DWORD
# phkResult : HKEY* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。