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

ClusterAddGroupToAffinityRule

関数
アフィニティルールにクラスターグループを追加する。
DLLCLUSAPI.dll呼出規約winapi

シグネチャ

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

DWORD ClusterAddGroupToAffinityRule(
    HCLUSTER hCluster,
    LPCWSTR ruleName,
    HGROUP hGroup
);

パラメーター

名前方向説明
hClusterHCLUSTERin対象クラスタへのハンドル。
ruleNameLPCWSTRinグループを追加するアフィニティルールの名前を指すワイド文字列。
hGroupHGROUPinアフィニティルールへ追加するグループへのハンドル。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

ClusterAddGroupToAffinityRule = ctypes.windll.clusapi.ClusterAddGroupToAffinityRule
ClusterAddGroupToAffinityRule.restype = wintypes.DWORD
ClusterAddGroupToAffinityRule.argtypes = [
    ctypes.c_ssize_t,  # hCluster : HCLUSTER
    wintypes.LPCWSTR,  # ruleName : LPCWSTR
    ctypes.c_ssize_t,  # hGroup : HGROUP
]
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterAddGroupToAffinityRule = clusapi.NewProc("ClusterAddGroupToAffinityRule")
)

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

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

typedef ClusterAddGroupToAffinityRuleNative = Uint32 Function(IntPtr, Pointer<Utf16>, IntPtr);
typedef ClusterAddGroupToAffinityRuleDart = int Function(int, Pointer<Utf16>, int);
final ClusterAddGroupToAffinityRule = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<ClusterAddGroupToAffinityRuleNative, ClusterAddGroupToAffinityRuleDart>('ClusterAddGroupToAffinityRule');
// hCluster : HCLUSTER -> IntPtr
// ruleName : LPCWSTR -> Pointer<Utf16>
// hGroup : HGROUP -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterAddGroupToAffinityRule(
  hCluster: NativeInt;   // HCLUSTER
  ruleName: PWideChar;   // LPCWSTR
  hGroup: NativeInt   // HGROUP
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'ClusterAddGroupToAffinityRule';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ClusterAddGroupToAffinityRule"
  c_ClusterAddGroupToAffinityRule :: CIntPtr -> CWString -> CIntPtr -> IO Word32
-- hCluster : HCLUSTER -> CIntPtr
-- ruleName : LPCWSTR -> CWString
-- hGroup : HGROUP -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("ClusterAddGroupToAffinityRule" cluster-add-group-to-affinity-rule :convention :stdcall) :uint32
  (h-cluster :int64)   ; HCLUSTER
  (rule-name (:string :encoding :utf-16le))   ; LPCWSTR
  (h-group :int64))   ; HGROUP
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterAddGroupToAffinityRule = Win32::API::More->new('CLUSAPI',
    'DWORD ClusterAddGroupToAffinityRule(LPARAM hCluster, LPCWSTR ruleName, LPARAM hGroup)');
# my $ret = $ClusterAddGroupToAffinityRule->Call($hCluster, $ruleName, $hGroup);
# hCluster : HCLUSTER -> LPARAM
# ruleName : LPCWSTR -> LPCWSTR
# hGroup : HGROUP -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。