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

ClusterRegCreateKey

関数
クラスターレジストリ内にサブキーを作成または開く。
DLLCLUSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

INT ClusterRegCreateKey(
    HKEY hKey,
    LPCWSTR lpszSubKey,
    DWORD dwOptions,
    DWORD samDesired,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    HKEY* phkResult,
    DWORD* lpdwDisposition   // optional
);

パラメーター

名前型方向説明
hKeyHKEYin開かれているクラスターデータベースキーのハンドル。このパラメーターを NULL にすることはできません。
lpszSubKeyLPCWSTRin

作成または開くサブキーの名前を指定する、null で終わる Unicode 文字列へのポインター。 lpszSubKey パラメーターは、次の条件を満たすサブキーを指している必要があります。

  • hKey で識別されるキーの子キーであること。
  • 円記号 ( \ ) で始まっていないこと。
  • NULL でないこと。
lpszSubKey パラメーターは空の文字列を指すこともできます。その場合、 ClusterRegCreateKey は hKey が表すデータベースキーのハンドルを返します。
dwOptionsDWORDin

このキーに対する特別なオプションを指定します。現在、dwOptions には次の値を 設定できます。

REG_OPTION_NON_VOLATILE (0x00000000)

開かれた、または作成されたキーは不揮発性です。情報はシステムの再起動後も保持されます。

samDesiredDWORDin

新しいキーに必要なセキュリティアクセスを指定するアクセスマスク。次の値が有効です。

詳細については、 レジストリキーのセキュリティとアクセス権 を参照してください。

ACCESS_SYSTEM_SECURITY (0x01000000)

システムセキュリティにアクセスする権限。 システムアクセス制御リスト (SACL) へのアクセスを示すために 使用されます。この種類のアクセスでは、呼び出し元プロセスが SE_SECURITY_NAME (監査と セキュリティログの管理) 特権を持っている必要があります。

DELETE (0x00010000)

削除する権限。

KEY_ALL_ACCESS (0x000F003F)

KEY_QUERY_VALUE、KEY_ENUMERATE_SUB_KEYS、 KEY_NOTIFY、KEY_CREATE_SUB_KEY、 KEY_CREATE_LINK、KEY_SET_VALUE の各アクセスの組み合わせ。

KEY_CREATE_LINK (0x00000020)

シンボリックリンクを作成する権限。

KEY_ENUMERATE_SUB_KEYS (0x00000008)

サブキーを列挙する権限。

KEY_EXECUTE (0x00020019)

読み取りアクセスの権限。

KEY_NOTIFY (0x00000010)

変更通知の権限。

KEY_QUERY_VALUE (0x00000001)

サブキーのデータを照会する権限。

KEY_READ (0x00020019)

KEY_QUERY_VALUE、KEY_ENUMERATE_SUB_KEYS、 KEY_NOTIFY の各アクセスの組み合わせ。

KEY_SET_VALUE (0x00000002)

サブキーのデータを変更する権限。

KEY_WRITE (0x00020006)

KEY_SET_VALUE と KEY_CREATE_SUB_KEY の 各アクセスの組み合わせ。

READ_CONTROL (0x00020000)

セキュリティ記述子の所有者、グループ、および 随意アクセス制御リスト (DACL) を読み取る権限。

WRITE_DAC (0x00040000)

DACL に書き込む権限。

WRITE_OWNER (0x00080000)

所有者を変更する権限。

lpSecurityAttributesSECURITY_ATTRIBUTES*inoptionalこのパラメーターは無視されます。新しいレジストリキーにセキュリティ属性を設定するには、 ClusterRegCreateKey が正常に戻った後で ClusterRegSetKeySecurity 関数を 呼び出してください。
phkResultHKEY*out開かれた、または作成されたキーのハンドルへのポインター。
lpdwDispositionDWORD*outoptional

lpszSubKey が指すキーが開かれたのか作成されたのかを示す値への ポインター。次の値が有効です。

REG_CREATED_NEW_KEY (0x00000001)

キーは存在しなかったため、作成されました。

REG_OPENED_EXISTING_KEY (0x00000002)

キーは存在していたため、開かれました。

戻り値の型: INT

公式ドキュメント

指定したクラスターデータベースキーを作成します。キーがデータベースに既に存在する場合、ClusterRegCreateKey は変更を加えずにそのキーを開きます。

戻り値

操作が成功した場合、この関数は ERROR_SUCCESS を返します。

操作が失敗した場合、この関数は システムエラーコード を返します。

解説(Remarks)

呼び出し元は、ClusterRegCreateKey 関数で作成したキーのハンドルが不要になったら、 ClusterRegCloseKey を呼び出して ハンドルを閉じる必要があります。

次のリソース DLL のエントリポイント関数からは、ClusterRegCreateKey を 呼び出さないでください。

ClusterRegCreateKey は、これ以外のリソース DLL のエントリポイント関数や ワーカースレッドからであれば安全に呼び出すことができます。詳細については、 リソース DLL で呼び出しを避けるべき関数 を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

ClusterRegCreateKey = ctypes.windll.clusapi.ClusterRegCreateKey
ClusterRegCreateKey.restype = ctypes.c_int
ClusterRegCreateKey.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpszSubKey : LPCWSTR
    wintypes.DWORD,  # dwOptions : DWORD
    wintypes.DWORD,  # samDesired : DWORD
    ctypes.c_void_p,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    ctypes.c_void_p,  # phkResult : HKEY* out
    ctypes.POINTER(wintypes.DWORD),  # lpdwDisposition : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterRegCreateKey = clusapi.NewProc("ClusterRegCreateKey")
)

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

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

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

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

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

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

関連項目

類似 API
公式の関連項目
使用する型