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

WsCreateServiceHost

関数
エンドポイントからサービスホストを作成する。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WsCreateServiceHost(
    const WS_SERVICE_ENDPOINT** endpoints,   // optional
    WORD endpointCount,
    const WS_SERVICE_PROPERTY* serviceProperties,   // optional
    DWORD servicePropertyCount,
    WS_SERVICE_HOST** serviceHost,
    WS_ERROR* error   // optional
);

パラメーター

名前方向説明
endpointsWS_SERVICE_ENDPOINT**inoptional公開するサービスエンドポイントの配列WS_SERVICE_ENDPOINT*。
endpointCountWORDinendpoints配列の要素数を指定するWORD値。
servicePropertiesWS_SERVICE_PROPERTY*inoptionalサービスホストのプロパティ配列WS_SERVICE_PROPERTY。不要ならNULL可。
servicePropertyCountDWORDinserviceProperties配列の要素数を指定する。
serviceHostWS_SERVICE_HOST**out生成されたWS_SERVICE_HOSTを受け取る出力ポインタ。
errorWS_ERROR*inoptional詳細なエラー情報を格納するWS_ERRORオブジェクト。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WsCreateServiceHost(
    const WS_SERVICE_ENDPOINT** endpoints,   // optional
    WORD endpointCount,
    const WS_SERVICE_PROPERTY* serviceProperties,   // optional
    DWORD servicePropertyCount,
    WS_SERVICE_HOST** serviceHost,
    WS_ERROR* error   // optional
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsCreateServiceHost(
    IntPtr endpoints,   // WS_SERVICE_ENDPOINT** optional
    ushort endpointCount,   // WORD
    IntPtr serviceProperties,   // WS_SERVICE_PROPERTY* optional
    uint servicePropertyCount,   // DWORD
    IntPtr serviceHost,   // WS_SERVICE_HOST** out
    IntPtr error   // WS_ERROR* optional
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsCreateServiceHost(
    endpoints As IntPtr,   ' WS_SERVICE_ENDPOINT** optional
    endpointCount As UShort,   ' WORD
    serviceProperties As IntPtr,   ' WS_SERVICE_PROPERTY* optional
    servicePropertyCount As UInteger,   ' DWORD
    serviceHost As IntPtr,   ' WS_SERVICE_HOST** out
    [error] As IntPtr   ' WS_ERROR* optional
) As Integer
End Function
' endpoints : WS_SERVICE_ENDPOINT** optional
' endpointCount : WORD
' serviceProperties : WS_SERVICE_PROPERTY* optional
' servicePropertyCount : DWORD
' serviceHost : WS_SERVICE_HOST** out
' error : WS_ERROR* optional
Declare PtrSafe Function WsCreateServiceHost Lib "webservices" ( _
    ByVal endpoints As LongPtr, _
    ByVal endpointCount As Integer, _
    ByVal serviceProperties As LongPtr, _
    ByVal servicePropertyCount As Long, _
    ByVal serviceHost As LongPtr, _
    ByVal error As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WsCreateServiceHost = ctypes.windll.webservices.WsCreateServiceHost
WsCreateServiceHost.restype = ctypes.c_int
WsCreateServiceHost.argtypes = [
    ctypes.c_void_p,  # endpoints : WS_SERVICE_ENDPOINT** optional
    ctypes.c_ushort,  # endpointCount : WORD
    ctypes.c_void_p,  # serviceProperties : WS_SERVICE_PROPERTY* optional
    wintypes.DWORD,  # servicePropertyCount : DWORD
    ctypes.c_void_p,  # serviceHost : WS_SERVICE_HOST** out
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('webservices.dll')
WsCreateServiceHost = Fiddle::Function.new(
  lib['WsCreateServiceHost'],
  [
    Fiddle::TYPE_VOIDP,  # endpoints : WS_SERVICE_ENDPOINT** optional
    -Fiddle::TYPE_SHORT,  # endpointCount : WORD
    Fiddle::TYPE_VOIDP,  # serviceProperties : WS_SERVICE_PROPERTY* optional
    -Fiddle::TYPE_INT,  # servicePropertyCount : DWORD
    Fiddle::TYPE_VOIDP,  # serviceHost : WS_SERVICE_HOST** out
    Fiddle::TYPE_VOIDP,  # error : WS_ERROR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "webservices")]
extern "system" {
    fn WsCreateServiceHost(
        endpoints: *const *const WS_SERVICE_ENDPOINT,  // WS_SERVICE_ENDPOINT** optional
        endpointCount: u16,  // WORD
        serviceProperties: *const WS_SERVICE_PROPERTY,  // WS_SERVICE_PROPERTY* optional
        servicePropertyCount: u32,  // DWORD
        serviceHost: *mut *mut isize,  // WS_SERVICE_HOST** out
        error: *mut isize  // WS_ERROR* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("webservices.dll")]
public static extern int WsCreateServiceHost(IntPtr endpoints, ushort endpointCount, IntPtr serviceProperties, uint servicePropertyCount, IntPtr serviceHost, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsCreateServiceHost' -Namespace Win32 -PassThru
# $api::WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
#uselib "webservices.dll"
#func global WsCreateServiceHost "WsCreateServiceHost" sptr, sptr, sptr, sptr, sptr, sptr
; WsCreateServiceHost varptr(endpoints), endpointCount, varptr(serviceProperties), servicePropertyCount, varptr(serviceHost), varptr(error)   ; 戻り値は stat
; endpoints : WS_SERVICE_ENDPOINT** optional -> "sptr"
; endpointCount : WORD -> "sptr"
; serviceProperties : WS_SERVICE_PROPERTY* optional -> "sptr"
; servicePropertyCount : DWORD -> "sptr"
; serviceHost : WS_SERVICE_HOST** out -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "webservices.dll"
#cfunc global WsCreateServiceHost "WsCreateServiceHost" var, int, var, int, var, var
; res = WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
; endpoints : WS_SERVICE_ENDPOINT** optional -> "var"
; endpointCount : WORD -> "int"
; serviceProperties : WS_SERVICE_PROPERTY* optional -> "var"
; servicePropertyCount : DWORD -> "int"
; serviceHost : WS_SERVICE_HOST** out -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WsCreateServiceHost(WS_SERVICE_ENDPOINT** endpoints, WORD endpointCount, WS_SERVICE_PROPERTY* serviceProperties, DWORD servicePropertyCount, WS_SERVICE_HOST** serviceHost, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsCreateServiceHost "WsCreateServiceHost" var, int, var, int, var, var
; res = WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
; endpoints : WS_SERVICE_ENDPOINT** optional -> "var"
; endpointCount : WORD -> "int"
; serviceProperties : WS_SERVICE_PROPERTY* optional -> "var"
; servicePropertyCount : DWORD -> "int"
; serviceHost : WS_SERVICE_HOST** out -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsCreateServiceHost = webservices.NewProc("WsCreateServiceHost")
)

// endpoints (WS_SERVICE_ENDPOINT** optional), endpointCount (WORD), serviceProperties (WS_SERVICE_PROPERTY* optional), servicePropertyCount (DWORD), serviceHost (WS_SERVICE_HOST** out), error (WS_ERROR* optional)
r1, _, err := procWsCreateServiceHost.Call(
	uintptr(endpoints),
	uintptr(endpointCount),
	uintptr(serviceProperties),
	uintptr(servicePropertyCount),
	uintptr(serviceHost),
	uintptr(error),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WsCreateServiceHost(
  endpoints: Pointer;   // WS_SERVICE_ENDPOINT** optional
  endpointCount: Word;   // WORD
  serviceProperties: Pointer;   // WS_SERVICE_PROPERTY* optional
  servicePropertyCount: DWORD;   // DWORD
  serviceHost: Pointer;   // WS_SERVICE_HOST** out
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsCreateServiceHost';
result := DllCall("webservices\WsCreateServiceHost"
    , "Ptr", endpoints   ; WS_SERVICE_ENDPOINT** optional
    , "UShort", endpointCount   ; WORD
    , "Ptr", serviceProperties   ; WS_SERVICE_PROPERTY* optional
    , "UInt", servicePropertyCount   ; DWORD
    , "Ptr", serviceHost   ; WS_SERVICE_HOST** out
    , "Ptr", error   ; WS_ERROR* optional
    , "Int")   ; return: HRESULT
●WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error) = DLL("webservices.dll", "int WsCreateServiceHost(void*, int, void*, dword, void*, void*)")
# 呼び出し: WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
# endpoints : WS_SERVICE_ENDPOINT** optional -> "void*"
# endpointCount : WORD -> "int"
# serviceProperties : WS_SERVICE_PROPERTY* optional -> "void*"
# servicePropertyCount : DWORD -> "dword"
# serviceHost : WS_SERVICE_HOST** out -> "void*"
# error : WS_ERROR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "webservices" fn WsCreateServiceHost(
    endpoints: [*c][*c]WS_SERVICE_ENDPOINT, // WS_SERVICE_ENDPOINT** optional
    endpointCount: u16, // WORD
    serviceProperties: [*c]WS_SERVICE_PROPERTY, // WS_SERVICE_PROPERTY* optional
    servicePropertyCount: u32, // DWORD
    serviceHost: [*c][*c]isize, // WS_SERVICE_HOST** out
    error: [*c]isize // WS_ERROR* optional
) callconv(std.os.windows.WINAPI) i32;
proc WsCreateServiceHost(
    endpoints: ptr WS_SERVICE_ENDPOINT,  # WS_SERVICE_ENDPOINT** optional
    endpointCount: uint16,  # WORD
    serviceProperties: ptr WS_SERVICE_PROPERTY,  # WS_SERVICE_PROPERTY* optional
    servicePropertyCount: uint32,  # DWORD
    serviceHost: ptr int,  # WS_SERVICE_HOST** out
    error: ptr int  # WS_ERROR* optional
): int32 {.importc: "WsCreateServiceHost", stdcall, dynlib: "webservices.dll".}
pragma(lib, "webservices");
extern(Windows)
int WsCreateServiceHost(
    WS_SERVICE_ENDPOINT** endpoints,   // WS_SERVICE_ENDPOINT** optional
    ushort endpointCount,   // WORD
    WS_SERVICE_PROPERTY* serviceProperties,   // WS_SERVICE_PROPERTY* optional
    uint servicePropertyCount,   // DWORD
    ptrdiff_t** serviceHost,   // WS_SERVICE_HOST** out
    ptrdiff_t* error   // WS_ERROR* optional
);
ccall((:WsCreateServiceHost, "webservices.dll"), stdcall, Int32,
      (Ptr{WS_SERVICE_ENDPOINT}, UInt16, Ptr{WS_SERVICE_PROPERTY}, UInt32, Ptr{Int}, Ptr{Int}),
      endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
# endpoints : WS_SERVICE_ENDPOINT** optional -> Ptr{WS_SERVICE_ENDPOINT}
# endpointCount : WORD -> UInt16
# serviceProperties : WS_SERVICE_PROPERTY* optional -> Ptr{WS_SERVICE_PROPERTY}
# servicePropertyCount : DWORD -> UInt32
# serviceHost : WS_SERVICE_HOST** out -> Ptr{Int}
# error : WS_ERROR* optional -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WsCreateServiceHost(
    void* endpoints,
    uint16_t endpointCount,
    void* serviceProperties,
    uint32_t servicePropertyCount,
    intptr_t** serviceHost,
    intptr_t* error);
]]
local webservices = ffi.load("webservices")
-- webservices.WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
-- endpoints : WS_SERVICE_ENDPOINT** optional
-- endpointCount : WORD
-- serviceProperties : WS_SERVICE_PROPERTY* optional
-- servicePropertyCount : DWORD
-- serviceHost : WS_SERVICE_HOST** out
-- error : WS_ERROR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('webservices.dll');
const WsCreateServiceHost = lib.func('__stdcall', 'WsCreateServiceHost', 'int32_t', ['void *', 'uint16_t', 'void *', 'uint32_t', 'intptr_t *', 'intptr_t *']);
// WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
// endpoints : WS_SERVICE_ENDPOINT** optional -> 'void *'
// endpointCount : WORD -> 'uint16_t'
// serviceProperties : WS_SERVICE_PROPERTY* optional -> 'void *'
// servicePropertyCount : DWORD -> 'uint32_t'
// serviceHost : WS_SERVICE_HOST** out -> 'intptr_t *'
// error : WS_ERROR* optional -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("webservices.dll", {
  WsCreateServiceHost: { parameters: ["pointer", "u16", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error)
// endpoints : WS_SERVICE_ENDPOINT** optional -> "pointer"
// endpointCount : WORD -> "u16"
// serviceProperties : WS_SERVICE_PROPERTY* optional -> "pointer"
// servicePropertyCount : DWORD -> "u32"
// serviceHost : WS_SERVICE_HOST** out -> "pointer"
// error : WS_ERROR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WsCreateServiceHost(
    void* endpoints,
    uint16_t endpointCount,
    void* serviceProperties,
    uint32_t servicePropertyCount,
    intptr_t** serviceHost,
    intptr_t* error);
C, "webservices.dll");
// $ffi->WsCreateServiceHost(endpoints, endpointCount, serviceProperties, servicePropertyCount, serviceHost, error);
// endpoints : WS_SERVICE_ENDPOINT** optional
// endpointCount : WORD
// serviceProperties : WS_SERVICE_PROPERTY* optional
// servicePropertyCount : DWORD
// serviceHost : WS_SERVICE_HOST** out
// error : WS_ERROR* 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 Webservices extends StdCallLibrary {
    Webservices INSTANCE = Native.load("webservices", Webservices.class);
    int WsCreateServiceHost(
        Pointer endpoints,   // WS_SERVICE_ENDPOINT** optional
        short endpointCount,   // WORD
        Pointer serviceProperties,   // WS_SERVICE_PROPERTY* optional
        int servicePropertyCount,   // DWORD
        Pointer serviceHost,   // WS_SERVICE_HOST** out
        LongByReference error   // WS_ERROR* optional
    );
}
@[Link("webservices")]
lib Libwebservices
  fun WsCreateServiceHost = WsCreateServiceHost(
    endpoints : WS_SERVICE_ENDPOINT**,   # WS_SERVICE_ENDPOINT** optional
    endpointCount : UInt16,   # WORD
    serviceProperties : WS_SERVICE_PROPERTY*,   # WS_SERVICE_PROPERTY* optional
    servicePropertyCount : UInt32,   # DWORD
    serviceHost : LibC::SSizeT**,   # WS_SERVICE_HOST** out
    error : LibC::SSizeT*   # WS_ERROR* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WsCreateServiceHostNative = Int32 Function(Pointer<Void>, Uint16, Pointer<Void>, Uint32, Pointer<IntPtr>, Pointer<IntPtr>);
typedef WsCreateServiceHostDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<IntPtr>, Pointer<IntPtr>);
final WsCreateServiceHost = DynamicLibrary.open('webservices.dll')
    .lookupFunction<WsCreateServiceHostNative, WsCreateServiceHostDart>('WsCreateServiceHost');
// endpoints : WS_SERVICE_ENDPOINT** optional -> Pointer<Void>
// endpointCount : WORD -> Uint16
// serviceProperties : WS_SERVICE_PROPERTY* optional -> Pointer<Void>
// servicePropertyCount : DWORD -> Uint32
// serviceHost : WS_SERVICE_HOST** out -> Pointer<IntPtr>
// error : WS_ERROR* optional -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WsCreateServiceHost(
  endpoints: Pointer;   // WS_SERVICE_ENDPOINT** optional
  endpointCount: Word;   // WORD
  serviceProperties: Pointer;   // WS_SERVICE_PROPERTY* optional
  servicePropertyCount: DWORD;   // DWORD
  serviceHost: Pointer;   // WS_SERVICE_HOST** out
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsCreateServiceHost';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WsCreateServiceHost"
  c_WsCreateServiceHost :: Ptr () -> Word16 -> Ptr () -> Word32 -> Ptr CIntPtr -> Ptr CIntPtr -> IO Int32
-- endpoints : WS_SERVICE_ENDPOINT** optional -> Ptr ()
-- endpointCount : WORD -> Word16
-- serviceProperties : WS_SERVICE_PROPERTY* optional -> Ptr ()
-- servicePropertyCount : DWORD -> Word32
-- serviceHost : WS_SERVICE_HOST** out -> Ptr CIntPtr
-- error : WS_ERROR* optional -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wscreateservicehost =
  foreign "WsCreateServiceHost"
    ((ptr void) @-> uint16_t @-> (ptr void) @-> uint32_t @-> (ptr intptr_t) @-> (ptr intptr_t) @-> returning int32_t)
(* endpoints : WS_SERVICE_ENDPOINT** optional -> (ptr void) *)
(* endpointCount : WORD -> uint16_t *)
(* serviceProperties : WS_SERVICE_PROPERTY* optional -> (ptr void) *)
(* servicePropertyCount : DWORD -> uint32_t *)
(* serviceHost : WS_SERVICE_HOST** out -> (ptr intptr_t) *)
(* error : WS_ERROR* optional -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library webservices (t "webservices.dll"))
(cffi:use-foreign-library webservices)

(cffi:defcfun ("WsCreateServiceHost" ws-create-service-host :convention :stdcall) :int32
  (endpoints :pointer)   ; WS_SERVICE_ENDPOINT** optional
  (endpoint-count :uint16)   ; WORD
  (service-properties :pointer)   ; WS_SERVICE_PROPERTY* optional
  (service-property-count :uint32)   ; DWORD
  (service-host :pointer)   ; WS_SERVICE_HOST** out
  (error :pointer))   ; WS_ERROR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WsCreateServiceHost = Win32::API::More->new('webservices',
    'int WsCreateServiceHost(LPVOID endpoints, WORD endpointCount, LPVOID serviceProperties, DWORD servicePropertyCount, LPVOID serviceHost, LPVOID error)');
# my $ret = $WsCreateServiceHost->Call($endpoints, $endpointCount, $serviceProperties, $servicePropertyCount, $serviceHost, $error);
# endpoints : WS_SERVICE_ENDPOINT** optional -> LPVOID
# endpointCount : WORD -> WORD
# serviceProperties : WS_SERVICE_PROPERTY* optional -> LPVOID
# servicePropertyCount : DWORD -> DWORD
# serviceHost : WS_SERVICE_HOST** out -> LPVOID
# error : WS_ERROR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型