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

HttpCreateServerSession

関数
HTTPサーバーセッションを作成する。
DLLHTTPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD HttpCreateServerSession(
    HTTPAPI_VERSION Version,
    ULONGLONG* ServerSessionId,
    DWORD Reserved   // optional
);

パラメーター

名前方向説明
VersionHTTPAPI_VERSIONin

サーバーセッションのバージョンを示す HTTPAPI_VERSION 構造体です。バージョン 2.0 の場合は、構造体のインスタンスを宣言し、あらかじめ定義された値 HTTPAPI_VERSION_2 を設定してから HttpCreateServerSession に渡します。

バージョンは 2.0 でなければなりません。HttpCreateServerSession はバージョン 1.0 の要求キューをサポートしません。

ServerSessionIdULONGLONG*outサーバーセッションの ID を受け取る変数へのポインターです。
ReservedDWORDinoptional予約済みです。0 でなければなりません。

戻り値の型: DWORD

公式ドキュメント

指定したバージョンのサーバーセッションを作成します。

戻り値

関数が成功した場合は NO_ERROR を返します。

関数が失敗した場合は、次のいずれかのエラーコードを返します。

意味
ERROR_REVISION_MISMATCH
渡されたバージョンが無効か、サポートされていません。
ERROR_INVALID_PARAMETER
pServerSessionId パラメーターが null であるか、Reserved が 0 以外です。

解説(Remarks)

サーバーセッションは一連の URL グループを所有します。サーバーセッションは、その下に作成されるすべての URL グループに適用される構成情報を格納する、最上位の構成コンテナーです。サーバーセッションの構成について詳しくは、HttpSetServerSessionProperty を参照してください。

HTTP Server API は、サーバーセッションに対する非同期 I/O をサポートしません。

サーバーセッションが不要になったとき、またはアプリケーションを終了する前に、アプリケーションは HttpCloseServerSession を呼び出してサーバーセッションを削除しなければなりません。サーバーセッションが削除されると、関連付けられたすべての URL グループも自動的に削除されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD HttpCreateServerSession(
    HTTPAPI_VERSION Version,
    ULONGLONG* ServerSessionId,
    DWORD Reserved   // optional
);
[DllImport("HTTPAPI.dll", ExactSpelling = true)]
static extern uint HttpCreateServerSession(
    HTTPAPI_VERSION Version,   // HTTPAPI_VERSION
    out ulong ServerSessionId,   // ULONGLONG* out
    uint Reserved   // DWORD optional
);
<DllImport("HTTPAPI.dll", ExactSpelling:=True)>
Public Shared Function HttpCreateServerSession(
    Version As HTTPAPI_VERSION,   ' HTTPAPI_VERSION
    <Out> ByRef ServerSessionId As ULong,   ' ULONGLONG* out
    Reserved As UInteger   ' DWORD optional
) As UInteger
End Function
' Version : HTTPAPI_VERSION
' ServerSessionId : ULONGLONG* out
' Reserved : DWORD optional
Declare PtrSafe Function HttpCreateServerSession Lib "httpapi" ( _
    ByVal Version As LongPtr, _
    ByRef ServerSessionId As LongLong, _
    ByVal Reserved As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HttpCreateServerSession = ctypes.windll.httpapi.HttpCreateServerSession
HttpCreateServerSession.restype = wintypes.DWORD
HttpCreateServerSession.argtypes = [
    HTTPAPI_VERSION,  # Version : HTTPAPI_VERSION
    ctypes.POINTER(ctypes.c_ulonglong),  # ServerSessionId : ULONGLONG* out
    wintypes.DWORD,  # Reserved : DWORD optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('HTTPAPI.dll')
HttpCreateServerSession = Fiddle::Function.new(
  lib['HttpCreateServerSession'],
  [
    Fiddle::TYPE_VOIDP,  # Version : HTTPAPI_VERSION
    Fiddle::TYPE_VOIDP,  # ServerSessionId : ULONGLONG* out
    -Fiddle::TYPE_INT,  # Reserved : DWORD optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "httpapi")]
extern "system" {
    fn HttpCreateServerSession(
        Version: HTTPAPI_VERSION,  // HTTPAPI_VERSION
        ServerSessionId: *mut u64,  // ULONGLONG* out
        Reserved: u32  // DWORD optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("HTTPAPI.dll")]
public static extern uint HttpCreateServerSession(HTTPAPI_VERSION Version, out ulong ServerSessionId, uint Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'HTTPAPI_HttpCreateServerSession' -Namespace Win32 -PassThru
# $api::HttpCreateServerSession(Version, ServerSessionId, Reserved)
#uselib "HTTPAPI.dll"
#func global HttpCreateServerSession "HttpCreateServerSession" sptr, sptr, sptr
; HttpCreateServerSession Version, varptr(ServerSessionId), Reserved   ; 戻り値は stat
; Version : HTTPAPI_VERSION -> "sptr"
; ServerSessionId : ULONGLONG* out -> "sptr"
; Reserved : DWORD optional -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "HTTPAPI.dll"
#cfunc global HttpCreateServerSession "HttpCreateServerSession" int, var, int
; res = HttpCreateServerSession(Version, ServerSessionId, Reserved)
; Version : HTTPAPI_VERSION -> "int"
; ServerSessionId : ULONGLONG* out -> "var"
; Reserved : DWORD optional -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD HttpCreateServerSession(HTTPAPI_VERSION Version, ULONGLONG* ServerSessionId, DWORD Reserved)
#uselib "HTTPAPI.dll"
#cfunc global HttpCreateServerSession "HttpCreateServerSession" int, var, int
; res = HttpCreateServerSession(Version, ServerSessionId, Reserved)
; Version : HTTPAPI_VERSION -> "int"
; ServerSessionId : ULONGLONG* out -> "var"
; Reserved : DWORD optional -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	httpapi = windows.NewLazySystemDLL("HTTPAPI.dll")
	procHttpCreateServerSession = httpapi.NewProc("HttpCreateServerSession")
)

// Version (HTTPAPI_VERSION), ServerSessionId (ULONGLONG* out), Reserved (DWORD optional)
r1, _, err := procHttpCreateServerSession.Call(
	uintptr(Version),
	uintptr(ServerSessionId),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function HttpCreateServerSession(
  Version: HTTPAPI_VERSION;   // HTTPAPI_VERSION
  ServerSessionId: Pointer;   // ULONGLONG* out
  Reserved: DWORD   // DWORD optional
): DWORD; stdcall;
  external 'HTTPAPI.dll' name 'HttpCreateServerSession';
result := DllCall("HTTPAPI\HttpCreateServerSession"
    , "Ptr", Version   ; HTTPAPI_VERSION
    , "Ptr", ServerSessionId   ; ULONGLONG* out
    , "UInt", Reserved   ; DWORD optional
    , "UInt")   ; return: DWORD
●HttpCreateServerSession(Version, ServerSessionId, Reserved) = DLL("HTTPAPI.dll", "dword HttpCreateServerSession(void*, void*, dword)")
# 呼び出し: HttpCreateServerSession(Version, ServerSessionId, Reserved)
# Version : HTTPAPI_VERSION -> "void*"
# ServerSessionId : ULONGLONG* out -> "void*"
# Reserved : DWORD optional -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "httpapi" fn HttpCreateServerSession(
    Version: HTTPAPI_VERSION, // HTTPAPI_VERSION
    ServerSessionId: [*c]u64, // ULONGLONG* out
    Reserved: u32 // DWORD optional
) callconv(std.os.windows.WINAPI) u32;
proc HttpCreateServerSession(
    Version: HTTPAPI_VERSION,  # HTTPAPI_VERSION
    ServerSessionId: ptr uint64,  # ULONGLONG* out
    Reserved: uint32  # DWORD optional
): uint32 {.importc: "HttpCreateServerSession", stdcall, dynlib: "HTTPAPI.dll".}
pragma(lib, "httpapi");
extern(Windows)
uint HttpCreateServerSession(
    HTTPAPI_VERSION Version,   // HTTPAPI_VERSION
    ulong* ServerSessionId,   // ULONGLONG* out
    uint Reserved   // DWORD optional
);
ccall((:HttpCreateServerSession, "HTTPAPI.dll"), stdcall, UInt32,
      (HTTPAPI_VERSION, Ptr{UInt64}, UInt32),
      Version, ServerSessionId, Reserved)
# Version : HTTPAPI_VERSION -> HTTPAPI_VERSION
# ServerSessionId : ULONGLONG* out -> Ptr{UInt64}
# Reserved : DWORD optional -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t HttpCreateServerSession(
    HTTPAPI_VERSION Version,
    uint64_t* ServerSessionId,
    uint32_t Reserved);
]]
local httpapi = ffi.load("httpapi")
-- httpapi.HttpCreateServerSession(Version, ServerSessionId, Reserved)
-- Version : HTTPAPI_VERSION
-- ServerSessionId : ULONGLONG* out
-- Reserved : DWORD optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('HTTPAPI.dll');
const HttpCreateServerSession = lib.func('__stdcall', 'HttpCreateServerSession', 'uint32_t', ['HTTPAPI_VERSION', 'uint64_t *', 'uint32_t']);
// HttpCreateServerSession(Version, ServerSessionId, Reserved)
// Version : HTTPAPI_VERSION -> 'HTTPAPI_VERSION'
// ServerSessionId : ULONGLONG* out -> 'uint64_t *'
// Reserved : DWORD optional -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("HTTPAPI.dll", {
  HttpCreateServerSession: { parameters: ["buffer", "pointer", "u32"], result: "u32" },
});
// lib.symbols.HttpCreateServerSession(Version, ServerSessionId, Reserved)
// Version : HTTPAPI_VERSION -> "buffer"
// ServerSessionId : ULONGLONG* out -> "pointer"
// Reserved : DWORD optional -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t HttpCreateServerSession(
    HTTPAPI_VERSION Version,
    uint64_t* ServerSessionId,
    uint32_t Reserved);
C, "HTTPAPI.dll");
// $ffi->HttpCreateServerSession(Version, ServerSessionId, Reserved);
// Version : HTTPAPI_VERSION
// ServerSessionId : ULONGLONG* out
// Reserved : DWORD 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 Httpapi extends StdCallLibrary {
    Httpapi INSTANCE = Native.load("httpapi", Httpapi.class);
    int HttpCreateServerSession(
        HTTPAPI_VERSION /* extends Structure (by value) */ Version,   // HTTPAPI_VERSION
        LongByReference ServerSessionId,   // ULONGLONG* out
        int Reserved   // DWORD optional
    );
}
@[Link("httpapi")]
lib LibHTTPAPI
  fun HttpCreateServerSession = HttpCreateServerSession(
    Version : HTTPAPI_VERSION,   # HTTPAPI_VERSION
    ServerSessionId : UInt64*,   # ULONGLONG* out
    Reserved : UInt32   # DWORD optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef HttpCreateServerSessionNative = Uint32 Function(HTTPAPI_VERSION, Pointer<Uint64>, Uint32);
typedef HttpCreateServerSessionDart = int Function(int, Pointer<Uint64>, int);
final HttpCreateServerSession = DynamicLibrary.open('HTTPAPI.dll')
    .lookupFunction<HttpCreateServerSessionNative, HttpCreateServerSessionDart>('HttpCreateServerSession');
// Version : HTTPAPI_VERSION -> HTTPAPI_VERSION
// ServerSessionId : ULONGLONG* out -> Pointer<Uint64>
// Reserved : DWORD optional -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function HttpCreateServerSession(
  Version: HTTPAPI_VERSION;   // HTTPAPI_VERSION
  ServerSessionId: Pointer;   // ULONGLONG* out
  Reserved: DWORD   // DWORD optional
): DWORD; stdcall;
  external 'HTTPAPI.dll' name 'HttpCreateServerSession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "HttpCreateServerSession"
  c_HttpCreateServerSession :: HTTPAPI_VERSION -> Ptr Word64 -> Word32 -> IO Word32
-- Version : HTTPAPI_VERSION -> HTTPAPI_VERSION
-- ServerSessionId : ULONGLONG* out -> Ptr Word64
-- Reserved : DWORD optional -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let httpcreateserversession =
  foreign "HttpCreateServerSession"
    (HTTPAPI_VERSION @-> (ptr uint64_t) @-> uint32_t @-> returning uint32_t)
(* Version : HTTPAPI_VERSION -> HTTPAPI_VERSION *)
(* ServerSessionId : ULONGLONG* out -> (ptr uint64_t) *)
(* Reserved : DWORD optional -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library httpapi (t "HTTPAPI.dll"))
(cffi:use-foreign-library httpapi)

(cffi:defcfun ("HttpCreateServerSession" http-create-server-session :convention :stdcall) :uint32
  (version (:struct httpapi-version))   ; HTTPAPI_VERSION
  (server-session-id :pointer)   ; ULONGLONG* out
  (reserved :uint32))   ; DWORD optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HttpCreateServerSession = Win32::API::More->new('HTTPAPI',
    'DWORD HttpCreateServerSession(LPVOID Version, LPVOID ServerSessionId, DWORD Reserved)');
# my $ret = $HttpCreateServerSession->Call($Version, $ServerSessionId, $Reserved);
# Version : HTTPAPI_VERSION -> LPVOID
# ServerSessionId : ULONGLONG* out -> LPVOID
# Reserved : DWORD optional -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型