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

SetClusterNameEx

関数
理由を付与してクラスターの名前を変更する。
DLLCLUSAPI.dll呼出規約winapi

シグネチャ

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

DWORD SetClusterNameEx(
    HCLUSTER hCluster,
    LPCWSTR lpszNewClusterName,
    LPCWSTR lpszReason   // optional
);

パラメーター

名前方向
hClusterHCLUSTERin
lpszNewClusterNameLPCWSTRin
lpszReasonLPCWSTRinoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

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

SetClusterNameEx = ctypes.windll.clusapi.SetClusterNameEx
SetClusterNameEx.restype = wintypes.DWORD
SetClusterNameEx.argtypes = [
    ctypes.c_ssize_t,  # hCluster : HCLUSTER
    wintypes.LPCWSTR,  # lpszNewClusterName : LPCWSTR
    wintypes.LPCWSTR,  # lpszReason : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procSetClusterNameEx = clusapi.NewProc("SetClusterNameEx")
)

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