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

WsAsyncExecute

関数
非同期操作を実行する。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WsAsyncExecute(
    WS_ASYNC_STATE* asyncState,
    WS_ASYNC_FUNCTION operation,
    WS_CALLBACK_MODEL callbackModel,
    void* callbackState,   // optional
    const WS_ASYNC_CONTEXT* asyncContext,   // optional
    WS_ERROR* error   // optional
);

パラメーター

名前方向説明
asyncStateWS_ASYNC_STATE*in非同期操作の進行状態を保持するWS_ASYNC_STATE。
operationWS_ASYNC_FUNCTIONin非同期に実行する関数へのポインタ。
callbackModelWS_CALLBACK_MODELinコールバックの実行モデル(短時間/長時間)を示す列挙値。
callbackStatevoid*inoptionaloperationやコールバックに渡すユーザー定義状態。NULL可。
asyncContextWS_ASYNC_CONTEXT*inoptional呼び出し元の非同期コンテキスト。同期実行ならNULL。
errorWS_ERROR*inoptional失敗時の追加エラー情報を格納するWS_ERRORオブジェクト。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WsAsyncExecute(
    WS_ASYNC_STATE* asyncState,
    WS_ASYNC_FUNCTION operation,
    WS_CALLBACK_MODEL callbackModel,
    void* callbackState,   // optional
    const WS_ASYNC_CONTEXT* asyncContext,   // optional
    WS_ERROR* error   // optional
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsAsyncExecute(
    IntPtr asyncState,   // WS_ASYNC_STATE*
    IntPtr operation,   // WS_ASYNC_FUNCTION
    int callbackModel,   // WS_CALLBACK_MODEL
    IntPtr callbackState,   // void* optional
    IntPtr asyncContext,   // WS_ASYNC_CONTEXT* optional
    IntPtr error   // WS_ERROR* optional
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsAsyncExecute(
    asyncState As IntPtr,   ' WS_ASYNC_STATE*
    operation As IntPtr,   ' WS_ASYNC_FUNCTION
    callbackModel As Integer,   ' WS_CALLBACK_MODEL
    callbackState As IntPtr,   ' void* optional
    asyncContext As IntPtr,   ' WS_ASYNC_CONTEXT* optional
    [error] As IntPtr   ' WS_ERROR* optional
) As Integer
End Function
' asyncState : WS_ASYNC_STATE*
' operation : WS_ASYNC_FUNCTION
' callbackModel : WS_CALLBACK_MODEL
' callbackState : void* optional
' asyncContext : WS_ASYNC_CONTEXT* optional
' error : WS_ERROR* optional
Declare PtrSafe Function WsAsyncExecute Lib "webservices" ( _
    ByVal asyncState As LongPtr, _
    ByVal operation As LongPtr, _
    ByVal callbackModel As Long, _
    ByVal callbackState As LongPtr, _
    ByVal asyncContext 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

WsAsyncExecute = ctypes.windll.webservices.WsAsyncExecute
WsAsyncExecute.restype = ctypes.c_int
WsAsyncExecute.argtypes = [
    ctypes.c_void_p,  # asyncState : WS_ASYNC_STATE*
    ctypes.c_void_p,  # operation : WS_ASYNC_FUNCTION
    ctypes.c_int,  # callbackModel : WS_CALLBACK_MODEL
    ctypes.POINTER(None),  # callbackState : void* optional
    ctypes.c_void_p,  # asyncContext : WS_ASYNC_CONTEXT* optional
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('webservices.dll')
WsAsyncExecute = Fiddle::Function.new(
  lib['WsAsyncExecute'],
  [
    Fiddle::TYPE_VOIDP,  # asyncState : WS_ASYNC_STATE*
    Fiddle::TYPE_VOIDP,  # operation : WS_ASYNC_FUNCTION
    Fiddle::TYPE_INT,  # callbackModel : WS_CALLBACK_MODEL
    Fiddle::TYPE_VOIDP,  # callbackState : void* optional
    Fiddle::TYPE_VOIDP,  # asyncContext : WS_ASYNC_CONTEXT* optional
    Fiddle::TYPE_VOIDP,  # error : WS_ERROR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "webservices")]
extern "system" {
    fn WsAsyncExecute(
        asyncState: *mut WS_ASYNC_STATE,  // WS_ASYNC_STATE*
        operation: *const core::ffi::c_void,  // WS_ASYNC_FUNCTION
        callbackModel: i32,  // WS_CALLBACK_MODEL
        callbackState: *mut (),  // void* optional
        asyncContext: *const WS_ASYNC_CONTEXT,  // WS_ASYNC_CONTEXT* optional
        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 WsAsyncExecute(IntPtr asyncState, IntPtr operation, int callbackModel, IntPtr callbackState, IntPtr asyncContext, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsAsyncExecute' -Namespace Win32 -PassThru
# $api::WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
#uselib "webservices.dll"
#func global WsAsyncExecute "WsAsyncExecute" sptr, sptr, sptr, sptr, sptr, sptr
; WsAsyncExecute varptr(asyncState), operation, callbackModel, callbackState, varptr(asyncContext), varptr(error)   ; 戻り値は stat
; asyncState : WS_ASYNC_STATE* -> "sptr"
; operation : WS_ASYNC_FUNCTION -> "sptr"
; callbackModel : WS_CALLBACK_MODEL -> "sptr"
; callbackState : void* optional -> "sptr"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "webservices.dll"
#cfunc global WsAsyncExecute "WsAsyncExecute" var, sptr, int, sptr, var, var
; res = WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
; asyncState : WS_ASYNC_STATE* -> "var"
; operation : WS_ASYNC_FUNCTION -> "sptr"
; callbackModel : WS_CALLBACK_MODEL -> "int"
; callbackState : void* optional -> "sptr"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WsAsyncExecute(WS_ASYNC_STATE* asyncState, WS_ASYNC_FUNCTION operation, WS_CALLBACK_MODEL callbackModel, void* callbackState, WS_ASYNC_CONTEXT* asyncContext, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsAsyncExecute "WsAsyncExecute" var, intptr, int, intptr, var, var
; res = WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
; asyncState : WS_ASYNC_STATE* -> "var"
; operation : WS_ASYNC_FUNCTION -> "intptr"
; callbackModel : WS_CALLBACK_MODEL -> "int"
; callbackState : void* optional -> "intptr"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsAsyncExecute = webservices.NewProc("WsAsyncExecute")
)

// asyncState (WS_ASYNC_STATE*), operation (WS_ASYNC_FUNCTION), callbackModel (WS_CALLBACK_MODEL), callbackState (void* optional), asyncContext (WS_ASYNC_CONTEXT* optional), error (WS_ERROR* optional)
r1, _, err := procWsAsyncExecute.Call(
	uintptr(asyncState),
	uintptr(operation),
	uintptr(callbackModel),
	uintptr(callbackState),
	uintptr(asyncContext),
	uintptr(error),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WsAsyncExecute(
  asyncState: Pointer;   // WS_ASYNC_STATE*
  operation: Pointer;   // WS_ASYNC_FUNCTION
  callbackModel: Integer;   // WS_CALLBACK_MODEL
  callbackState: Pointer;   // void* optional
  asyncContext: Pointer;   // WS_ASYNC_CONTEXT* optional
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsAsyncExecute';
result := DllCall("webservices\WsAsyncExecute"
    , "Ptr", asyncState   ; WS_ASYNC_STATE*
    , "Ptr", operation   ; WS_ASYNC_FUNCTION
    , "Int", callbackModel   ; WS_CALLBACK_MODEL
    , "Ptr", callbackState   ; void* optional
    , "Ptr", asyncContext   ; WS_ASYNC_CONTEXT* optional
    , "Ptr", error   ; WS_ERROR* optional
    , "Int")   ; return: HRESULT
●WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error) = DLL("webservices.dll", "int WsAsyncExecute(void*, void*, int, void*, void*, void*)")
# 呼び出し: WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
# asyncState : WS_ASYNC_STATE* -> "void*"
# operation : WS_ASYNC_FUNCTION -> "void*"
# callbackModel : WS_CALLBACK_MODEL -> "int"
# callbackState : void* optional -> "void*"
# asyncContext : WS_ASYNC_CONTEXT* optional -> "void*"
# error : WS_ERROR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "webservices" fn WsAsyncExecute(
    asyncState: [*c]WS_ASYNC_STATE, // WS_ASYNC_STATE*
    operation: ?*anyopaque, // WS_ASYNC_FUNCTION
    callbackModel: i32, // WS_CALLBACK_MODEL
    callbackState: ?*anyopaque, // void* optional
    asyncContext: [*c]WS_ASYNC_CONTEXT, // WS_ASYNC_CONTEXT* optional
    error: [*c]isize // WS_ERROR* optional
) callconv(std.os.windows.WINAPI) i32;
proc WsAsyncExecute(
    asyncState: ptr WS_ASYNC_STATE,  # WS_ASYNC_STATE*
    operation: pointer,  # WS_ASYNC_FUNCTION
    callbackModel: int32,  # WS_CALLBACK_MODEL
    callbackState: pointer,  # void* optional
    asyncContext: ptr WS_ASYNC_CONTEXT,  # WS_ASYNC_CONTEXT* optional
    error: ptr int  # WS_ERROR* optional
): int32 {.importc: "WsAsyncExecute", stdcall, dynlib: "webservices.dll".}
pragma(lib, "webservices");
extern(Windows)
int WsAsyncExecute(
    WS_ASYNC_STATE* asyncState,   // WS_ASYNC_STATE*
    void* operation,   // WS_ASYNC_FUNCTION
    int callbackModel,   // WS_CALLBACK_MODEL
    void* callbackState,   // void* optional
    WS_ASYNC_CONTEXT* asyncContext,   // WS_ASYNC_CONTEXT* optional
    ptrdiff_t* error   // WS_ERROR* optional
);
ccall((:WsAsyncExecute, "webservices.dll"), stdcall, Int32,
      (Ptr{WS_ASYNC_STATE}, Ptr{Cvoid}, Int32, Ptr{Cvoid}, Ptr{WS_ASYNC_CONTEXT}, Ptr{Int}),
      asyncState, operation, callbackModel, callbackState, asyncContext, error)
# asyncState : WS_ASYNC_STATE* -> Ptr{WS_ASYNC_STATE}
# operation : WS_ASYNC_FUNCTION -> Ptr{Cvoid}
# callbackModel : WS_CALLBACK_MODEL -> Int32
# callbackState : void* optional -> Ptr{Cvoid}
# asyncContext : WS_ASYNC_CONTEXT* optional -> Ptr{WS_ASYNC_CONTEXT}
# error : WS_ERROR* optional -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WsAsyncExecute(
    void* asyncState,
    void* operation,
    int32_t callbackModel,
    void* callbackState,
    void* asyncContext,
    intptr_t* error);
]]
local webservices = ffi.load("webservices")
-- webservices.WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
-- asyncState : WS_ASYNC_STATE*
-- operation : WS_ASYNC_FUNCTION
-- callbackModel : WS_CALLBACK_MODEL
-- callbackState : void* optional
-- asyncContext : WS_ASYNC_CONTEXT* optional
-- error : WS_ERROR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('webservices.dll');
const WsAsyncExecute = lib.func('__stdcall', 'WsAsyncExecute', 'int32_t', ['void *', 'void *', 'int32_t', 'void *', 'void *', 'intptr_t *']);
// WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
// asyncState : WS_ASYNC_STATE* -> 'void *'
// operation : WS_ASYNC_FUNCTION -> 'void *'
// callbackModel : WS_CALLBACK_MODEL -> 'int32_t'
// callbackState : void* optional -> 'void *'
// asyncContext : WS_ASYNC_CONTEXT* optional -> 'void *'
// error : WS_ERROR* optional -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("webservices.dll", {
  WsAsyncExecute: { parameters: ["pointer", "pointer", "i32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error)
// asyncState : WS_ASYNC_STATE* -> "pointer"
// operation : WS_ASYNC_FUNCTION -> "pointer"
// callbackModel : WS_CALLBACK_MODEL -> "i32"
// callbackState : void* optional -> "pointer"
// asyncContext : WS_ASYNC_CONTEXT* optional -> "pointer"
// error : WS_ERROR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WsAsyncExecute(
    void* asyncState,
    void* operation,
    int32_t callbackModel,
    void* callbackState,
    void* asyncContext,
    intptr_t* error);
C, "webservices.dll");
// $ffi->WsAsyncExecute(asyncState, operation, callbackModel, callbackState, asyncContext, error);
// asyncState : WS_ASYNC_STATE*
// operation : WS_ASYNC_FUNCTION
// callbackModel : WS_CALLBACK_MODEL
// callbackState : void* optional
// asyncContext : WS_ASYNC_CONTEXT* optional
// 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 WsAsyncExecute(
        Pointer asyncState,   // WS_ASYNC_STATE*
        Callback operation,   // WS_ASYNC_FUNCTION
        int callbackModel,   // WS_CALLBACK_MODEL
        Pointer callbackState,   // void* optional
        Pointer asyncContext,   // WS_ASYNC_CONTEXT* optional
        LongByReference error   // WS_ERROR* optional
    );
}
@[Link("webservices")]
lib Libwebservices
  fun WsAsyncExecute = WsAsyncExecute(
    asyncState : WS_ASYNC_STATE*,   # WS_ASYNC_STATE*
    operation : Void*,   # WS_ASYNC_FUNCTION
    callbackModel : Int32,   # WS_CALLBACK_MODEL
    callbackState : Void*,   # void* optional
    asyncContext : WS_ASYNC_CONTEXT*,   # WS_ASYNC_CONTEXT* optional
    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 WsAsyncExecuteNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef WsAsyncExecuteDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final WsAsyncExecute = DynamicLibrary.open('webservices.dll')
    .lookupFunction<WsAsyncExecuteNative, WsAsyncExecuteDart>('WsAsyncExecute');
// asyncState : WS_ASYNC_STATE* -> Pointer<Void>
// operation : WS_ASYNC_FUNCTION -> Pointer<Void>
// callbackModel : WS_CALLBACK_MODEL -> Int32
// callbackState : void* optional -> Pointer<Void>
// asyncContext : WS_ASYNC_CONTEXT* optional -> Pointer<Void>
// error : WS_ERROR* optional -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WsAsyncExecute(
  asyncState: Pointer;   // WS_ASYNC_STATE*
  operation: Pointer;   // WS_ASYNC_FUNCTION
  callbackModel: Integer;   // WS_CALLBACK_MODEL
  callbackState: Pointer;   // void* optional
  asyncContext: Pointer;   // WS_ASYNC_CONTEXT* optional
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsAsyncExecute';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WsAsyncExecute"
  c_WsAsyncExecute :: Ptr () -> Ptr () -> Int32 -> Ptr () -> Ptr () -> Ptr CIntPtr -> IO Int32
-- asyncState : WS_ASYNC_STATE* -> Ptr ()
-- operation : WS_ASYNC_FUNCTION -> Ptr ()
-- callbackModel : WS_CALLBACK_MODEL -> Int32
-- callbackState : void* optional -> Ptr ()
-- asyncContext : WS_ASYNC_CONTEXT* optional -> Ptr ()
-- error : WS_ERROR* optional -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsasyncexecute =
  foreign "WsAsyncExecute"
    ((ptr void) @-> (ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning int32_t)
(* asyncState : WS_ASYNC_STATE* -> (ptr void) *)
(* operation : WS_ASYNC_FUNCTION -> (ptr void) *)
(* callbackModel : WS_CALLBACK_MODEL -> int32_t *)
(* callbackState : void* optional -> (ptr void) *)
(* asyncContext : WS_ASYNC_CONTEXT* optional -> (ptr void) *)
(* 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 ("WsAsyncExecute" ws-async-execute :convention :stdcall) :int32
  (async-state :pointer)   ; WS_ASYNC_STATE*
  (operation :pointer)   ; WS_ASYNC_FUNCTION
  (callback-model :int32)   ; WS_CALLBACK_MODEL
  (callback-state :pointer)   ; void* optional
  (async-context :pointer)   ; WS_ASYNC_CONTEXT* optional
  (error :pointer))   ; WS_ERROR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WsAsyncExecute = Win32::API::More->new('webservices',
    'int WsAsyncExecute(LPVOID asyncState, LPVOID operation, int callbackModel, LPVOID callbackState, LPVOID asyncContext, LPVOID error)');
# my $ret = $WsAsyncExecute->Call($asyncState, $operation, $callbackModel, $callbackState, $asyncContext, $error);
# asyncState : WS_ASYNC_STATE* -> LPVOID
# operation : WS_ASYNC_FUNCTION -> LPVOID
# callbackModel : WS_CALLBACK_MODEL -> int
# callbackState : void* optional -> LPVOID
# asyncContext : WS_ASYNC_CONTEXT* optional -> LPVOID
# error : WS_ERROR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型