Win32 API 日本語リファレンス
ホームGraphics.Printing › CreatePrintAsyncNotifyChannel

CreatePrintAsyncNotifyChannel

関数
印刷の非同期通知チャネルを作成する。
DLLwinspool.drv呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// winspool.drv
#include <windows.h>

HRESULT CreatePrintAsyncNotifyChannel(
    LPCWSTR pszName,   // optional
    GUID* pNotificationType,
    PrintAsyncNotifyUserFilter eUserFilter,
    PrintAsyncNotifyConversationStyle eConversationStyle,
    IPrintAsyncNotifyCallback* pCallback,   // optional
    IPrintAsyncNotifyChannel** ppIAsynchNotification
);

パラメーター

名前方向説明
pszNameLPCWSTRinoptionalプリントサーバーまたは印刷キューの名前へのポインター。
pNotificationTypeGUID*inチャネルで送信される通知の種類に対応するデータスキーマの GUID へのポインター。
eUserFilterPrintAsyncNotifyUserFilterin

通知の送信先を指定する値。次のいずれかを指定します。

  • Print Spooler がホストするプラグイン (送信側) と同じユーザーとして実行されているアプリケーションのみ。
  • より広範囲の、リッスンしているアプリケーション。
eConversationStylePrintAsyncNotifyConversationStylein通信が双方向か単方向かを指定する値。
pCallbackIPrintAsyncNotifyCallback*inoptionalリッスンしているアプリケーションが、Print Spooler がホストするコンポーネントをコールバックするために使用するオブジェクトへのポインター。directionalitykUniDirectional の場合は NULL にする必要があります。
ppIAsynchNotificationIPrintAsyncNotifyChannel**out新しいチャネルへのポインター。

戻り値の型: HRESULT

公式ドキュメント

Print Spooler がホストする印刷コンポーネント (プリンタードライバーやポートモニターなど) と、そのコンポーネントから通知を受け取るアプリケーションとの間に通信チャネルを作成します。

戻り値

HRESULT 重大度 意味
S_OK SUCCESS 関数は正常に完了しました。
CHANNEL_ALREADY_OPENED ERROR チャネルは既に開かれています。
MAX_CHANNEL_COUNT_EXCEEDED ERROR 指定されたキューまたはプリントサーバーに対して、指定された種類の通知を受け取るリッスンしているアプリケーションが既に最大数まで登録されています。既定の最大数は 10,000 です。

戻り値は COM エラーコードです。この関数は処理に成功した場合でも S_OK 以外の HRESULT を返すことがあるため、呼び出しの成否を判断するには SUCCEEDED マクロまたは FAILED マクロを使用してください。関数が返した具体的な HRESULT を取得するには、HRESULT_CODE マクロを使用します。

次のコード例は、これらのマクロを使用して戻り値を評価する方法を示しています。

if (SUCCEEDED(hr)){
  //Call was successful 
}

if (FAILED(hr)) {
  // Call failed 
}

if (FAILED(hr)) {
  // Call failed 
  switch (HRESULT_CODE(hr)){
    case CHANNEL_ALREADY_OPENED:
      // Some action 
      break;
    case MAX_CHANNEL_COUNT_EXCEEDED:
      // Some action 
      break;
    default:
      //Default action 
      break;
  }
} else {
  //call succeeded 
}

COM エラーコードの詳細については、Error Handling を参照してください。

その他の返される可能性がある値については、PrintAsyncNotifyError を参照してください。

解説(Remarks)

注意 これはブロッキング関数 (同期関数) であり、すぐに制御が戻らない場合があります。この関数が返るまでの時間は、ネットワークの状態、プリントサーバーの構成、プリンタードライバーの実装など、アプリケーションの作成時には予測が困難な実行時の要因に左右されます。ユーザーインターフェイスとのやり取りを管理するスレッドからこの関数を呼び出すと、アプリケーションが応答していないように見えることがあります。
コンポーネントがチャネルを開けるのは、Print Spooler のプロセス内で実行されている場合だけです。たとえば、アプリケーションがプリンタードライバーを読み込んだ場合、そのドライバーはチャネルを開くことができませんが、Print Spooler 内に読み込まれたプリンタードライバーはチャネルを開くことができます。リッスンするアプリケーションは、Print Spooler のプロセスの内部と外部のどちらにあってもかまいません。

チャネルを閉じるには IPrintAsyncNotifyChannel::CloseChannel を呼び出します。ただし、IPrintAsyncNotifyChannel::CloseChannelCreatePrintAsyncNotifyChannel の呼び出し直後には呼び出せません。

IPrintAsyncNotifyChannel::Release() は、次の場合にのみ呼び出してください。

  1. 以前の IPrintAsyncNotifyChannel::AddRef() の呼び出しと明示的に対応している場合。
  2. チャネルが単方向 (UniDirectional) チャネルであり、CreatePrintAsyncNotifyChannel の呼び出しが成功して受け取ったポインターを破棄する場合。
  3. 双方向 (BiDirectional) チャネルを作成した後、または IPrintNotifyAsyncCallback::OnEventNotify の実装内で、次のいずれかに該当する場合。
    1. IPrintAsyncNotifyChannel::SendNotification または IPrintAsyncNotifyChannel::CloseChannel を呼び出さなかった場合、または
    2. 失敗した IPrintAsyncNotifyChannel::SendNotification または IPrintAsyncNotifyChannel::CloseChannel の呼び出しを再試行しなかった場合、または
    3. サーバー側で、戻り値 NO_LISTENER で成功した IPrintAsyncNotifyChannel::SendNotification の呼び出しを再試行しなかった場合、または
    4. クライアント側で、戻り値 CHANNEL_ACQUIRED で成功した IPrintAsyncNotifyChannel::SendNotification の呼び出しを再試行しなかった場合。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// winspool.drv
#include <windows.h>

HRESULT CreatePrintAsyncNotifyChannel(
    LPCWSTR pszName,   // optional
    GUID* pNotificationType,
    PrintAsyncNotifyUserFilter eUserFilter,
    PrintAsyncNotifyConversationStyle eConversationStyle,
    IPrintAsyncNotifyCallback* pCallback,   // optional
    IPrintAsyncNotifyChannel** ppIAsynchNotification
);
[DllImport("winspool.drv", ExactSpelling = true)]
static extern int CreatePrintAsyncNotifyChannel(
    [MarshalAs(UnmanagedType.LPWStr)] string pszName,   // LPCWSTR optional
    ref Guid pNotificationType,   // GUID*
    int eUserFilter,   // PrintAsyncNotifyUserFilter
    int eConversationStyle,   // PrintAsyncNotifyConversationStyle
    IntPtr pCallback,   // IPrintAsyncNotifyCallback* optional
    IntPtr ppIAsynchNotification   // IPrintAsyncNotifyChannel** out
);
<DllImport("winspool.drv", ExactSpelling:=True)>
Public Shared Function CreatePrintAsyncNotifyChannel(
    <MarshalAs(UnmanagedType.LPWStr)> pszName As String,   ' LPCWSTR optional
    ByRef pNotificationType As Guid,   ' GUID*
    eUserFilter As Integer,   ' PrintAsyncNotifyUserFilter
    eConversationStyle As Integer,   ' PrintAsyncNotifyConversationStyle
    pCallback As IntPtr,   ' IPrintAsyncNotifyCallback* optional
    ppIAsynchNotification As IntPtr   ' IPrintAsyncNotifyChannel** out
) As Integer
End Function
' pszName : LPCWSTR optional
' pNotificationType : GUID*
' eUserFilter : PrintAsyncNotifyUserFilter
' eConversationStyle : PrintAsyncNotifyConversationStyle
' pCallback : IPrintAsyncNotifyCallback* optional
' ppIAsynchNotification : IPrintAsyncNotifyChannel** out
Declare PtrSafe Function CreatePrintAsyncNotifyChannel Lib "winspool.drv" ( _
    ByVal pszName As LongPtr, _
    ByVal pNotificationType As LongPtr, _
    ByVal eUserFilter As Long, _
    ByVal eConversationStyle As Long, _
    ByVal pCallback As LongPtr, _
    ByVal ppIAsynchNotification As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreatePrintAsyncNotifyChannel = ctypes.windll.LoadLibrary("winspool.drv").CreatePrintAsyncNotifyChannel
CreatePrintAsyncNotifyChannel.restype = ctypes.c_int
CreatePrintAsyncNotifyChannel.argtypes = [
    wintypes.LPCWSTR,  # pszName : LPCWSTR optional
    ctypes.c_void_p,  # pNotificationType : GUID*
    ctypes.c_int,  # eUserFilter : PrintAsyncNotifyUserFilter
    ctypes.c_int,  # eConversationStyle : PrintAsyncNotifyConversationStyle
    ctypes.c_void_p,  # pCallback : IPrintAsyncNotifyCallback* optional
    ctypes.c_void_p,  # ppIAsynchNotification : IPrintAsyncNotifyChannel** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('winspool.drv')
CreatePrintAsyncNotifyChannel = Fiddle::Function.new(
  lib['CreatePrintAsyncNotifyChannel'],
  [
    Fiddle::TYPE_VOIDP,  # pszName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pNotificationType : GUID*
    Fiddle::TYPE_INT,  # eUserFilter : PrintAsyncNotifyUserFilter
    Fiddle::TYPE_INT,  # eConversationStyle : PrintAsyncNotifyConversationStyle
    Fiddle::TYPE_VOIDP,  # pCallback : IPrintAsyncNotifyCallback* optional
    Fiddle::TYPE_VOIDP,  # ppIAsynchNotification : IPrintAsyncNotifyChannel** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winspool.drv")]
extern "system" {
    fn CreatePrintAsyncNotifyChannel(
        pszName: *const u16,  // LPCWSTR optional
        pNotificationType: *mut GUID,  // GUID*
        eUserFilter: i32,  // PrintAsyncNotifyUserFilter
        eConversationStyle: i32,  // PrintAsyncNotifyConversationStyle
        pCallback: *mut core::ffi::c_void,  // IPrintAsyncNotifyCallback* optional
        ppIAsynchNotification: *mut *mut core::ffi::c_void  // IPrintAsyncNotifyChannel** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("winspool.drv")]
public static extern int CreatePrintAsyncNotifyChannel([MarshalAs(UnmanagedType.LPWStr)] string pszName, ref Guid pNotificationType, int eUserFilter, int eConversationStyle, IntPtr pCallback, IntPtr ppIAsynchNotification);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_CreatePrintAsyncNotifyChannel' -Namespace Win32 -PassThru
# $api::CreatePrintAsyncNotifyChannel(pszName, pNotificationType, eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification)
#uselib "winspool.drv"
#func global CreatePrintAsyncNotifyChannel "CreatePrintAsyncNotifyChannel" sptr, sptr, sptr, sptr, sptr, sptr
; CreatePrintAsyncNotifyChannel pszName, varptr(pNotificationType), eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification   ; 戻り値は stat
; pszName : LPCWSTR optional -> "sptr"
; pNotificationType : GUID* -> "sptr"
; eUserFilter : PrintAsyncNotifyUserFilter -> "sptr"
; eConversationStyle : PrintAsyncNotifyConversationStyle -> "sptr"
; pCallback : IPrintAsyncNotifyCallback* optional -> "sptr"
; ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "winspool.drv"
#cfunc global CreatePrintAsyncNotifyChannel "CreatePrintAsyncNotifyChannel" wstr, var, int, int, sptr, sptr
; res = CreatePrintAsyncNotifyChannel(pszName, pNotificationType, eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification)
; pszName : LPCWSTR optional -> "wstr"
; pNotificationType : GUID* -> "var"
; eUserFilter : PrintAsyncNotifyUserFilter -> "int"
; eConversationStyle : PrintAsyncNotifyConversationStyle -> "int"
; pCallback : IPrintAsyncNotifyCallback* optional -> "sptr"
; ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT CreatePrintAsyncNotifyChannel(LPCWSTR pszName, GUID* pNotificationType, PrintAsyncNotifyUserFilter eUserFilter, PrintAsyncNotifyConversationStyle eConversationStyle, IPrintAsyncNotifyCallback* pCallback, IPrintAsyncNotifyChannel** ppIAsynchNotification)
#uselib "winspool.drv"
#cfunc global CreatePrintAsyncNotifyChannel "CreatePrintAsyncNotifyChannel" wstr, var, int, int, intptr, intptr
; res = CreatePrintAsyncNotifyChannel(pszName, pNotificationType, eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification)
; pszName : LPCWSTR optional -> "wstr"
; pNotificationType : GUID* -> "var"
; eUserFilter : PrintAsyncNotifyUserFilter -> "int"
; eConversationStyle : PrintAsyncNotifyConversationStyle -> "int"
; pCallback : IPrintAsyncNotifyCallback* optional -> "intptr"
; ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winspool_drv = windows.NewLazySystemDLL("winspool.drv")
	procCreatePrintAsyncNotifyChannel = winspool_drv.NewProc("CreatePrintAsyncNotifyChannel")
)

// pszName (LPCWSTR optional), pNotificationType (GUID*), eUserFilter (PrintAsyncNotifyUserFilter), eConversationStyle (PrintAsyncNotifyConversationStyle), pCallback (IPrintAsyncNotifyCallback* optional), ppIAsynchNotification (IPrintAsyncNotifyChannel** out)
r1, _, err := procCreatePrintAsyncNotifyChannel.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszName))),
	uintptr(pNotificationType),
	uintptr(eUserFilter),
	uintptr(eConversationStyle),
	uintptr(pCallback),
	uintptr(ppIAsynchNotification),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CreatePrintAsyncNotifyChannel(
  pszName: PWideChar;   // LPCWSTR optional
  pNotificationType: PGUID;   // GUID*
  eUserFilter: Integer;   // PrintAsyncNotifyUserFilter
  eConversationStyle: Integer;   // PrintAsyncNotifyConversationStyle
  pCallback: Pointer;   // IPrintAsyncNotifyCallback* optional
  ppIAsynchNotification: Pointer   // IPrintAsyncNotifyChannel** out
): Integer; stdcall;
  external 'winspool.drv' name 'CreatePrintAsyncNotifyChannel';
result := DllCall("winspool.drv\CreatePrintAsyncNotifyChannel"
    , "WStr", pszName   ; LPCWSTR optional
    , "Ptr", pNotificationType   ; GUID*
    , "Int", eUserFilter   ; PrintAsyncNotifyUserFilter
    , "Int", eConversationStyle   ; PrintAsyncNotifyConversationStyle
    , "Ptr", pCallback   ; IPrintAsyncNotifyCallback* optional
    , "Ptr", ppIAsynchNotification   ; IPrintAsyncNotifyChannel** out
    , "Int")   ; return: HRESULT
●CreatePrintAsyncNotifyChannel(pszName, pNotificationType, eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification) = DLL("winspool.drv", "int CreatePrintAsyncNotifyChannel(char*, void*, int, int, void*, void*)")
# 呼び出し: CreatePrintAsyncNotifyChannel(pszName, pNotificationType, eUserFilter, eConversationStyle, pCallback, ppIAsynchNotification)
# pszName : LPCWSTR optional -> "char*"
# pNotificationType : GUID* -> "void*"
# eUserFilter : PrintAsyncNotifyUserFilter -> "int"
# eConversationStyle : PrintAsyncNotifyConversationStyle -> "int"
# pCallback : IPrintAsyncNotifyCallback* optional -> "void*"
# ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef CreatePrintAsyncNotifyChannelNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Int32, Int32, Pointer<Void>, Pointer<Void>);
typedef CreatePrintAsyncNotifyChannelDart = int Function(Pointer<Utf16>, Pointer<Void>, int, int, Pointer<Void>, Pointer<Void>);
final CreatePrintAsyncNotifyChannel = DynamicLibrary.open('winspool.drv')
    .lookupFunction<CreatePrintAsyncNotifyChannelNative, CreatePrintAsyncNotifyChannelDart>('CreatePrintAsyncNotifyChannel');
// pszName : LPCWSTR optional -> Pointer<Utf16>
// pNotificationType : GUID* -> Pointer<Void>
// eUserFilter : PrintAsyncNotifyUserFilter -> Int32
// eConversationStyle : PrintAsyncNotifyConversationStyle -> Int32
// pCallback : IPrintAsyncNotifyCallback* optional -> Pointer<Void>
// ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreatePrintAsyncNotifyChannel(
  pszName: PWideChar;   // LPCWSTR optional
  pNotificationType: PGUID;   // GUID*
  eUserFilter: Integer;   // PrintAsyncNotifyUserFilter
  eConversationStyle: Integer;   // PrintAsyncNotifyConversationStyle
  pCallback: Pointer;   // IPrintAsyncNotifyCallback* optional
  ppIAsynchNotification: Pointer   // IPrintAsyncNotifyChannel** out
): Integer; stdcall;
  external 'winspool.drv' name 'CreatePrintAsyncNotifyChannel';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreatePrintAsyncNotifyChannel"
  c_CreatePrintAsyncNotifyChannel :: CWString -> Ptr () -> Int32 -> Int32 -> Ptr () -> Ptr () -> IO Int32
-- pszName : LPCWSTR optional -> CWString
-- pNotificationType : GUID* -> Ptr ()
-- eUserFilter : PrintAsyncNotifyUserFilter -> Int32
-- eConversationStyle : PrintAsyncNotifyConversationStyle -> Int32
-- pCallback : IPrintAsyncNotifyCallback* optional -> Ptr ()
-- ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createprintasyncnotifychannel =
  foreign "CreatePrintAsyncNotifyChannel"
    ((ptr uint16_t) @-> (ptr void) @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pszName : LPCWSTR optional -> (ptr uint16_t) *)
(* pNotificationType : GUID* -> (ptr void) *)
(* eUserFilter : PrintAsyncNotifyUserFilter -> int32_t *)
(* eConversationStyle : PrintAsyncNotifyConversationStyle -> int32_t *)
(* pCallback : IPrintAsyncNotifyCallback* optional -> (ptr void) *)
(* ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winspool.drv (t "winspool.drv"))
(cffi:use-foreign-library winspool.drv)

(cffi:defcfun ("CreatePrintAsyncNotifyChannel" create-print-async-notify-channel :convention :stdcall) :int32
  (psz-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (p-notification-type :pointer)   ; GUID*
  (e-user-filter :int32)   ; PrintAsyncNotifyUserFilter
  (e-conversation-style :int32)   ; PrintAsyncNotifyConversationStyle
  (p-callback :pointer)   ; IPrintAsyncNotifyCallback* optional
  (pp-iasynch-notification :pointer))   ; IPrintAsyncNotifyChannel** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreatePrintAsyncNotifyChannel = Win32::API::More->new('winspool.drv',
    'int CreatePrintAsyncNotifyChannel(LPCWSTR pszName, LPVOID pNotificationType, int eUserFilter, int eConversationStyle, LPVOID pCallback, LPVOID ppIAsynchNotification)');
# my $ret = $CreatePrintAsyncNotifyChannel->Call($pszName, $pNotificationType, $eUserFilter, $eConversationStyle, $pCallback, $ppIAsynchNotification);
# pszName : LPCWSTR optional -> LPCWSTR
# pNotificationType : GUID* -> LPVOID
# eUserFilter : PrintAsyncNotifyUserFilter -> int
# eConversationStyle : PrintAsyncNotifyConversationStyle -> int
# pCallback : IPrintAsyncNotifyCallback* optional -> LPVOID
# ppIAsynchNotification : IPrintAsyncNotifyChannel** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型