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

CreateClusterResource

関数
グループ内に指定種別のクラスターリソースを作成する。
DLLCLUSAPI.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

HRESOURCE CreateClusterResource(
    HGROUP hGroup,
    LPCWSTR lpszResourceName,
    LPCWSTR lpszResourceType,
    DWORD dwFlags
);

パラメーター

名前方向説明
hGroupHGROUPinリソースを作成し所属させる対象グループのハンドル。
lpszResourceNameLPCWSTRin作成するリソースの名前を示すワイド文字列。
lpszResourceTypeLPCWSTRinリソースの種類を示すリソースタイプ名のワイド文字列。
dwFlagsDWORDin作成動作を制御するフラグ。CLUSTER_RESOURCE_*値で指定する。

戻り値の型: HRESOURCE

各言語での呼び出し定義

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

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

CreateClusterResource = ctypes.windll.clusapi.CreateClusterResource
CreateClusterResource.restype = ctypes.c_ssize_t
CreateClusterResource.argtypes = [
    ctypes.c_ssize_t,  # hGroup : HGROUP
    wintypes.LPCWSTR,  # lpszResourceName : LPCWSTR
    wintypes.LPCWSTR,  # lpszResourceType : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procCreateClusterResource = clusapi.NewProc("CreateClusterResource")
)

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

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

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

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

let createclusterresource =
  foreign "CreateClusterResource"
    (intptr_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning intptr_t)
(* hGroup : HGROUP -> intptr_t *)
(* lpszResourceName : LPCWSTR -> (ptr uint16_t) *)
(* lpszResourceType : LPCWSTR -> (ptr uint16_t) *)
(* dwFlags : 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 ("CreateClusterResource" create-cluster-resource :convention :stdcall) :int64
  (h-group :int64)   ; HGROUP
  (lpsz-resource-name (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-resource-type (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateClusterResource = Win32::API::More->new('CLUSAPI',
    'LPARAM CreateClusterResource(LPARAM hGroup, LPCWSTR lpszResourceName, LPCWSTR lpszResourceType, DWORD dwFlags)');
# my $ret = $CreateClusterResource->Call($hGroup, $lpszResourceName, $lpszResourceType, $dwFlags);
# hGroup : HGROUP -> LPARAM
# lpszResourceName : LPCWSTR -> LPCWSTR
# lpszResourceType : LPCWSTR -> LPCWSTR
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API