Win32 API 日本語リファレンス
ホームNetworkManagement.WindowsConnectionManager › OnDemandRegisterNotification

OnDemandRegisterNotification

関数
オンデマンド接続の変更通知コールバックを登録する。
DLLOnDemandConnRouteHelper.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

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

HRESULT OnDemandRegisterNotification(
    ONDEMAND_NOTIFICATION_CALLBACK callback,
    void* callbackContext,   // optional
    HANDLE* registrationHandle
);

パラメーター

名前方向説明
callbackONDEMAND_NOTIFICATION_CALLBACKin接続状態の変化時に呼ばれる通知コールバック関数へのポインター。
callbackContextvoid*inoptionalコールバックへ渡される任意のコンテキストへのポインター。NULL可。
registrationHandleHANDLE*out登録ハンドルを受け取る出力先。解除時に使用する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT OnDemandRegisterNotification(
    ONDEMAND_NOTIFICATION_CALLBACK callback,
    void* callbackContext,   // optional
    HANDLE* registrationHandle
);
[DllImport("OnDemandConnRouteHelper.dll", ExactSpelling = true)]
static extern int OnDemandRegisterNotification(
    IntPtr callback,   // ONDEMAND_NOTIFICATION_CALLBACK
    IntPtr callbackContext,   // void* optional
    IntPtr registrationHandle   // HANDLE* out
);
<DllImport("OnDemandConnRouteHelper.dll", ExactSpelling:=True)>
Public Shared Function OnDemandRegisterNotification(
    callback As IntPtr,   ' ONDEMAND_NOTIFICATION_CALLBACK
    callbackContext As IntPtr,   ' void* optional
    registrationHandle As IntPtr   ' HANDLE* out
) As Integer
End Function
' callback : ONDEMAND_NOTIFICATION_CALLBACK
' callbackContext : void* optional
' registrationHandle : HANDLE* out
Declare PtrSafe Function OnDemandRegisterNotification Lib "ondemandconnroutehelper" ( _
    ByVal callback As LongPtr, _
    ByVal callbackContext As LongPtr, _
    ByVal registrationHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

OnDemandRegisterNotification = ctypes.windll.ondemandconnroutehelper.OnDemandRegisterNotification
OnDemandRegisterNotification.restype = ctypes.c_int
OnDemandRegisterNotification.argtypes = [
    ctypes.c_void_p,  # callback : ONDEMAND_NOTIFICATION_CALLBACK
    ctypes.POINTER(None),  # callbackContext : void* optional
    ctypes.c_void_p,  # registrationHandle : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OnDemandConnRouteHelper.dll')
OnDemandRegisterNotification = Fiddle::Function.new(
  lib['OnDemandRegisterNotification'],
  [
    Fiddle::TYPE_VOIDP,  # callback : ONDEMAND_NOTIFICATION_CALLBACK
    Fiddle::TYPE_VOIDP,  # callbackContext : void* optional
    Fiddle::TYPE_VOIDP,  # registrationHandle : HANDLE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ondemandconnroutehelper")]
extern "system" {
    fn OnDemandRegisterNotification(
        callback: *const core::ffi::c_void,  // ONDEMAND_NOTIFICATION_CALLBACK
        callbackContext: *mut (),  // void* optional
        registrationHandle: *mut *mut core::ffi::c_void  // HANDLE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OnDemandConnRouteHelper.dll")]
public static extern int OnDemandRegisterNotification(IntPtr callback, IntPtr callbackContext, IntPtr registrationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OnDemandConnRouteHelper_OnDemandRegisterNotification' -Namespace Win32 -PassThru
# $api::OnDemandRegisterNotification(callback, callbackContext, registrationHandle)
#uselib "OnDemandConnRouteHelper.dll"
#func global OnDemandRegisterNotification "OnDemandRegisterNotification" sptr, sptr, sptr
; OnDemandRegisterNotification callback, callbackContext, registrationHandle   ; 戻り値は stat
; callback : ONDEMAND_NOTIFICATION_CALLBACK -> "sptr"
; callbackContext : void* optional -> "sptr"
; registrationHandle : HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OnDemandConnRouteHelper.dll"
#cfunc global OnDemandRegisterNotification "OnDemandRegisterNotification" sptr, sptr, sptr
; res = OnDemandRegisterNotification(callback, callbackContext, registrationHandle)
; callback : ONDEMAND_NOTIFICATION_CALLBACK -> "sptr"
; callbackContext : void* optional -> "sptr"
; registrationHandle : HANDLE* out -> "sptr"
; HRESULT OnDemandRegisterNotification(ONDEMAND_NOTIFICATION_CALLBACK callback, void* callbackContext, HANDLE* registrationHandle)
#uselib "OnDemandConnRouteHelper.dll"
#cfunc global OnDemandRegisterNotification "OnDemandRegisterNotification" intptr, intptr, intptr
; res = OnDemandRegisterNotification(callback, callbackContext, registrationHandle)
; callback : ONDEMAND_NOTIFICATION_CALLBACK -> "intptr"
; callbackContext : void* optional -> "intptr"
; registrationHandle : HANDLE* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ondemandconnroutehelper = windows.NewLazySystemDLL("OnDemandConnRouteHelper.dll")
	procOnDemandRegisterNotification = ondemandconnroutehelper.NewProc("OnDemandRegisterNotification")
)

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

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

typedef OnDemandRegisterNotificationNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef OnDemandRegisterNotificationDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final OnDemandRegisterNotification = DynamicLibrary.open('OnDemandConnRouteHelper.dll')
    .lookupFunction<OnDemandRegisterNotificationNative, OnDemandRegisterNotificationDart>('OnDemandRegisterNotification');
// callback : ONDEMAND_NOTIFICATION_CALLBACK -> Pointer<Void>
// callbackContext : void* optional -> Pointer<Void>
// registrationHandle : HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function OnDemandRegisterNotification(
  callback: Pointer;   // ONDEMAND_NOTIFICATION_CALLBACK
  callbackContext: Pointer;   // void* optional
  registrationHandle: Pointer   // HANDLE* out
): Integer; stdcall;
  external 'OnDemandConnRouteHelper.dll' name 'OnDemandRegisterNotification';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "OnDemandRegisterNotification"
  c_OnDemandRegisterNotification :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- callback : ONDEMAND_NOTIFICATION_CALLBACK -> Ptr ()
-- callbackContext : void* optional -> Ptr ()
-- registrationHandle : HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ondemandregisternotification =
  foreign "OnDemandRegisterNotification"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* callback : ONDEMAND_NOTIFICATION_CALLBACK -> (ptr void) *)
(* callbackContext : void* optional -> (ptr void) *)
(* registrationHandle : HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ondemandconnroutehelper (t "OnDemandConnRouteHelper.dll"))
(cffi:use-foreign-library ondemandconnroutehelper)

(cffi:defcfun ("OnDemandRegisterNotification" on-demand-register-notification :convention :stdcall) :int32
  (callback :pointer)   ; ONDEMAND_NOTIFICATION_CALLBACK
  (callback-context :pointer)   ; void* optional
  (registration-handle :pointer))   ; HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $OnDemandRegisterNotification = Win32::API::More->new('OnDemandConnRouteHelper',
    'int OnDemandRegisterNotification(LPVOID callback, LPVOID callbackContext, HANDLE registrationHandle)');
# my $ret = $OnDemandRegisterNotification->Call($callback, $callbackContext, $registrationHandle);
# callback : ONDEMAND_NOTIFICATION_CALLBACK -> LPVOID
# callbackContext : void* optional -> LPVOID
# registrationHandle : HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型