Win32 API 日本語リファレンス
ホームSystem.Com › CoTestCancel

CoTestCancel

関数
現在の呼び出しにキャンセル要求があるか確認する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CoTestCancel(void);

パラメーターなし。戻り値: HRESULT

公式ドキュメント

サーバー上で実行中の呼び出しがクライアントによってキャンセルされたかどうかを判定します。

戻り値

この関数は、標準の戻り値 E_FAILE_INVALIDARGE_OUTOFMEMORYE_UNEXPECTED に加えて、次の値を返すことがあります。

戻り値 説明
RPC_S_CALLPENDING
呼び出しはまだ保留中であり、クライアントによってキャンセルされていません。
RPC_E_CALL_CANCELED
呼び出しはクライアントによってキャンセルされました。

解説(Remarks)

サーバーオブジェクトは、クライアントのキャンセル要求を検出するために、復帰する前に少なくとも一度は CoTestCancel を呼び出す必要があります。これにより、クライアントがキャンセル要求を発行している場合にサーバーの不要な処理を省くことができ、またクライアントがキャンセルタイムアウトを RPC_C_CANCEL_INFINITE_TIMEOUT に設定している場合にはクライアントの待機時間を短縮できます。さらに、サーバーオブジェクトが保留中の呼び出しから復帰する前にキャンセル要求を検出すれば、それが作成または取得したメモリ、マーシャリングされたインターフェイス、ハンドルをクリーンアップできます。

CoTestCancelCoGetCallContext を呼び出して現在のキャンセルオブジェクト上の ICancelMethodCalls インターフェイスを取得し、続いて ICancelMethodCalls::TestCancel を呼び出します。カスタムマーシャリングを実装するオブジェクトは、まず CoSwitchCallContext を呼び出して適切な呼び出しコンテキストオブジェクトをインストールする必要があります。

この関数は、非同期呼び出しのキャンセルはテストしません。

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

各言語での呼び出し定義

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

HRESULT CoTestCancel(void);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoTestCancel();
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoTestCancel() As Integer
End Function
Declare PtrSafe Function CoTestCancel Lib "ole32" () As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoTestCancel = ctypes.windll.ole32.CoTestCancel
CoTestCancel.restype = ctypes.c_int
CoTestCancel.argtypes = []
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoTestCancel = Fiddle::Function.new(
  lib['CoTestCancel'],
  [],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoTestCancel() -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoTestCancel();
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoTestCancel' -Namespace Win32 -PassThru
# $api::CoTestCancel()
#uselib "OLE32.dll"
#func global CoTestCancel "CoTestCancel"
; CoTestCancel   ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLE32.dll"
#cfunc global CoTestCancel "CoTestCancel"
; res = CoTestCancel()
; HRESULT CoTestCancel()
#uselib "OLE32.dll"
#cfunc global CoTestCancel "CoTestCancel"
; res = CoTestCancel()
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoTestCancel = ole32.NewProc("CoTestCancel")
)

r1, _, err := procCoTestCancel.Call()
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoTestCancel: Integer; stdcall;
  external 'OLE32.dll' name 'CoTestCancel';
result := DllCall("OLE32\CoTestCancel", "Int")
●CoTestCancel() = DLL("OLE32.dll", "int CoTestCancel()")
# 呼び出し: CoTestCancel()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef CoTestCancelNative = Int32 Function();
typedef CoTestCancelDart = int Function();
final CoTestCancel = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<CoTestCancelNative, CoTestCancelDart>('CoTestCancel');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CoTestCancel: Integer; stdcall;
  external 'OLE32.dll' name 'CoTestCancel';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CoTestCancel"
  c_CoTestCancel :: IO Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cotestcancel =
  foreign "CoTestCancel"
    (void @-> returning int32_t)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("CoTestCancel" co-test-cancel :convention :stdcall) :int32)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CoTestCancel = Win32::API::More->new('OLE32',
    'int CoTestCancel()');
# my $ret = $CoTestCancel->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目