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

OpenCluster

関数
指定名のクラスターを開きハンドルを返す。
DLLCLUSAPI.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

HCLUSTER OpenCluster(
    LPCWSTR lpszClusterName   // optional
);

パラメーター

名前方向説明
lpszClusterNameLPCWSTRinoptional接続するクラスタ名を指すワイド文字列。ローカルクラスタへ接続する場合はNULL可。

戻り値の型: HCLUSTER

各言語での呼び出し定義

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

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

OpenCluster = ctypes.windll.clusapi.OpenCluster
OpenCluster.restype = ctypes.c_ssize_t
OpenCluster.argtypes = [
    wintypes.LPCWSTR,  # lpszClusterName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procOpenCluster = clusapi.NewProc("OpenCluster")
)

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

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

typedef OpenClusterNative = IntPtr Function(Pointer<Utf16>);
typedef OpenClusterDart = int Function(Pointer<Utf16>);
final OpenCluster = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<OpenClusterNative, OpenClusterDart>('OpenCluster');
// lpszClusterName : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function OpenCluster(
  lpszClusterName: PWideChar   // LPCWSTR optional
): NativeInt; stdcall;
  external 'CLUSAPI.dll' name 'OpenCluster';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "OpenCluster"
  c_OpenCluster :: CWString -> IO CIntPtr
-- lpszClusterName : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let opencluster =
  foreign "OpenCluster"
    ((ptr uint16_t) @-> returning intptr_t)
(* lpszClusterName : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("OpenCluster" open-cluster :convention :stdcall) :int64
  (lpsz-cluster-name (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $OpenCluster = Win32::API::More->new('CLUSAPI',
    'LPARAM OpenCluster(LPCWSTR lpszClusterName)');
# my $ret = $OpenCluster->Call($lpszClusterName);
# lpszClusterName : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API