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

GetClusterKey

関数
クラスター全体のレジストリキーを開いて取得する。
DLLCLUSAPI.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

HKEY GetClusterKey(
    HCLUSTER hCluster,
    DWORD samDesired
);

パラメーター

名前方向説明
hClusterHCLUSTERinクラスターデータベースのルートキーを取得する対象クラスターのハンドル。
samDesiredDWORDin開くレジストリキーに要求するアクセス権(KEY_READ等)。

戻り値の型: HKEY

各言語での呼び出し定義

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

HKEY GetClusterKey(
    HCLUSTER hCluster,
    DWORD samDesired
);
[DllImport("CLUSAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr GetClusterKey(
    IntPtr hCluster,   // HCLUSTER
    uint samDesired   // DWORD
);
<DllImport("CLUSAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetClusterKey(
    hCluster As IntPtr,   ' HCLUSTER
    samDesired As UInteger   ' DWORD
) As IntPtr
End Function
' hCluster : HCLUSTER
' samDesired : DWORD
Declare PtrSafe Function GetClusterKey Lib "clusapi" ( _
    ByVal hCluster As LongPtr, _
    ByVal samDesired As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetClusterKey = ctypes.windll.clusapi.GetClusterKey
GetClusterKey.restype = ctypes.c_void_p
GetClusterKey.argtypes = [
    ctypes.c_ssize_t,  # hCluster : HCLUSTER
    wintypes.DWORD,  # samDesired : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procGetClusterKey = clusapi.NewProc("GetClusterKey")
)

// hCluster (HCLUSTER), samDesired (DWORD)
r1, _, err := procGetClusterKey.Call(
	uintptr(hCluster),
	uintptr(samDesired),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HKEY
function GetClusterKey(
  hCluster: NativeInt;   // HCLUSTER
  samDesired: DWORD   // DWORD
): THandle; stdcall;
  external 'CLUSAPI.dll' name 'GetClusterKey';
result := DllCall("CLUSAPI\GetClusterKey"
    , "Ptr", hCluster   ; HCLUSTER
    , "UInt", samDesired   ; DWORD
    , "Ptr")   ; return: HKEY
●GetClusterKey(hCluster, samDesired) = DLL("CLUSAPI.dll", "void* GetClusterKey(int, dword)")
# 呼び出し: GetClusterKey(hCluster, samDesired)
# hCluster : HCLUSTER -> "int"
# samDesired : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef GetClusterKeyNative = Pointer<Void> Function(IntPtr, Uint32);
typedef GetClusterKeyDart = Pointer<Void> Function(int, int);
final GetClusterKey = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<GetClusterKeyNative, GetClusterKeyDart>('GetClusterKey');
// hCluster : HCLUSTER -> IntPtr
// samDesired : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetClusterKey(
  hCluster: NativeInt;   // HCLUSTER
  samDesired: DWORD   // DWORD
): THandle; stdcall;
  external 'CLUSAPI.dll' name 'GetClusterKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetClusterKey"
  c_GetClusterKey :: CIntPtr -> Word32 -> IO (Ptr ())
-- hCluster : HCLUSTER -> CIntPtr
-- samDesired : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getclusterkey =
  foreign "GetClusterKey"
    (intptr_t @-> uint32_t @-> returning (ptr void))
(* hCluster : HCLUSTER -> intptr_t *)
(* samDesired : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("GetClusterKey" get-cluster-key :convention :stdcall) :pointer
  (h-cluster :int64)   ; HCLUSTER
  (sam-desired :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetClusterKey = Win32::API::More->new('CLUSAPI',
    'HANDLE GetClusterKey(LPARAM hCluster, DWORD samDesired)');
# my $ret = $GetClusterKey->Call($hCluster, $samDesired);
# hCluster : HCLUSTER -> LPARAM
# samDesired : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。