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

RtmAddRouteToDest

関数
指定した宛先へのルートをルーティングテーブルに追加する。
DLLrtm.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

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

DWORD RtmAddRouteToDest(
    INT_PTR RtmRegHandle,
    INT_PTR* RouteHandle,
    RTM_NET_ADDRESS* DestAddress,
    RTM_ROUTE_INFO* RouteInfo,
    DWORD TimeToLive,
    INT_PTR RouteListHandle,
    DWORD NotifyType,
    INT_PTR NotifyHandle,
    DWORD* ChangeFlags
);

パラメーター

名前方向説明
RtmRegHandleINT_PTRinRtmRegisterEntityで取得したRTM登録ハンドル。
RouteHandleINT_PTR*inout追加または更新されたルートのハンドルを受け取るポインタ。入力で更新対象を指定する場合もある。
DestAddressRTM_NET_ADDRESS*inoutルートの宛先ネットワークアドレスを示すRTM_NET_ADDRESS構造体へのポインタ。
RouteInfoRTM_ROUTE_INFO*inout追加するルートの情報を格納したRTM_ROUTE_INFO構造体へのポインタ。
TimeToLiveDWORDinルートの有効期間(秒単位)。無期限はINFINITEを指定する。
RouteListHandleINT_PTRinルートを関連付けるルートリストのハンドル。不要なら0を指定する。
NotifyTypeDWORDin変更通知の種類を示す値。
NotifyHandleINT_PTRin変更通知に関連付けるハンドル。
ChangeFlagsDWORD*inoutこの操作によって生じた変更内容を示すフラグを受け取るポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RtmAddRouteToDest(
    INT_PTR RtmRegHandle,
    INT_PTR* RouteHandle,
    RTM_NET_ADDRESS* DestAddress,
    RTM_ROUTE_INFO* RouteInfo,
    DWORD TimeToLive,
    INT_PTR RouteListHandle,
    DWORD NotifyType,
    INT_PTR NotifyHandle,
    DWORD* ChangeFlags
);
[DllImport("rtm.dll", ExactSpelling = true)]
static extern uint RtmAddRouteToDest(
    IntPtr RtmRegHandle,   // INT_PTR
    ref IntPtr RouteHandle,   // INT_PTR* in/out
    IntPtr DestAddress,   // RTM_NET_ADDRESS* in/out
    IntPtr RouteInfo,   // RTM_ROUTE_INFO* in/out
    uint TimeToLive,   // DWORD
    IntPtr RouteListHandle,   // INT_PTR
    uint NotifyType,   // DWORD
    IntPtr NotifyHandle,   // INT_PTR
    ref uint ChangeFlags   // DWORD* in/out
);
<DllImport("rtm.dll", ExactSpelling:=True)>
Public Shared Function RtmAddRouteToDest(
    RtmRegHandle As IntPtr,   ' INT_PTR
    ByRef RouteHandle As IntPtr,   ' INT_PTR* in/out
    DestAddress As IntPtr,   ' RTM_NET_ADDRESS* in/out
    RouteInfo As IntPtr,   ' RTM_ROUTE_INFO* in/out
    TimeToLive As UInteger,   ' DWORD
    RouteListHandle As IntPtr,   ' INT_PTR
    NotifyType As UInteger,   ' DWORD
    NotifyHandle As IntPtr,   ' INT_PTR
    ByRef ChangeFlags As UInteger   ' DWORD* in/out
) As UInteger
End Function
' RtmRegHandle : INT_PTR
' RouteHandle : INT_PTR* in/out
' DestAddress : RTM_NET_ADDRESS* in/out
' RouteInfo : RTM_ROUTE_INFO* in/out
' TimeToLive : DWORD
' RouteListHandle : INT_PTR
' NotifyType : DWORD
' NotifyHandle : INT_PTR
' ChangeFlags : DWORD* in/out
Declare PtrSafe Function RtmAddRouteToDest Lib "rtm" ( _
    ByVal RtmRegHandle As LongPtr, _
    ByRef RouteHandle As LongPtr, _
    ByVal DestAddress As LongPtr, _
    ByVal RouteInfo As LongPtr, _
    ByVal TimeToLive As Long, _
    ByVal RouteListHandle As LongPtr, _
    ByVal NotifyType As Long, _
    ByVal NotifyHandle As LongPtr, _
    ByRef ChangeFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtmAddRouteToDest = ctypes.windll.rtm.RtmAddRouteToDest
RtmAddRouteToDest.restype = wintypes.DWORD
RtmAddRouteToDest.argtypes = [
    ctypes.c_ssize_t,  # RtmRegHandle : INT_PTR
    ctypes.POINTER(ctypes.c_ssize_t),  # RouteHandle : INT_PTR* in/out
    ctypes.c_void_p,  # DestAddress : RTM_NET_ADDRESS* in/out
    ctypes.c_void_p,  # RouteInfo : RTM_ROUTE_INFO* in/out
    wintypes.DWORD,  # TimeToLive : DWORD
    ctypes.c_ssize_t,  # RouteListHandle : INT_PTR
    wintypes.DWORD,  # NotifyType : DWORD
    ctypes.c_ssize_t,  # NotifyHandle : INT_PTR
    ctypes.POINTER(wintypes.DWORD),  # ChangeFlags : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('rtm.dll')
RtmAddRouteToDest = Fiddle::Function.new(
  lib['RtmAddRouteToDest'],
  [
    Fiddle::TYPE_INTPTR_T,  # RtmRegHandle : INT_PTR
    Fiddle::TYPE_VOIDP,  # RouteHandle : INT_PTR* in/out
    Fiddle::TYPE_VOIDP,  # DestAddress : RTM_NET_ADDRESS* in/out
    Fiddle::TYPE_VOIDP,  # RouteInfo : RTM_ROUTE_INFO* in/out
    -Fiddle::TYPE_INT,  # TimeToLive : DWORD
    Fiddle::TYPE_INTPTR_T,  # RouteListHandle : INT_PTR
    -Fiddle::TYPE_INT,  # NotifyType : DWORD
    Fiddle::TYPE_INTPTR_T,  # NotifyHandle : INT_PTR
    Fiddle::TYPE_VOIDP,  # ChangeFlags : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "rtm")]
extern "system" {
    fn RtmAddRouteToDest(
        RtmRegHandle: isize,  // INT_PTR
        RouteHandle: *mut isize,  // INT_PTR* in/out
        DestAddress: *mut RTM_NET_ADDRESS,  // RTM_NET_ADDRESS* in/out
        RouteInfo: *mut RTM_ROUTE_INFO,  // RTM_ROUTE_INFO* in/out
        TimeToLive: u32,  // DWORD
        RouteListHandle: isize,  // INT_PTR
        NotifyType: u32,  // DWORD
        NotifyHandle: isize,  // INT_PTR
        ChangeFlags: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("rtm.dll")]
public static extern uint RtmAddRouteToDest(IntPtr RtmRegHandle, ref IntPtr RouteHandle, IntPtr DestAddress, IntPtr RouteInfo, uint TimeToLive, IntPtr RouteListHandle, uint NotifyType, IntPtr NotifyHandle, ref uint ChangeFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'rtm_RtmAddRouteToDest' -Namespace Win32 -PassThru
# $api::RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
#uselib "rtm.dll"
#func global RtmAddRouteToDest "RtmAddRouteToDest" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; RtmAddRouteToDest RtmRegHandle, varptr(RouteHandle), varptr(DestAddress), varptr(RouteInfo), TimeToLive, RouteListHandle, NotifyType, NotifyHandle, varptr(ChangeFlags)   ; 戻り値は stat
; RtmRegHandle : INT_PTR -> "sptr"
; RouteHandle : INT_PTR* in/out -> "sptr"
; DestAddress : RTM_NET_ADDRESS* in/out -> "sptr"
; RouteInfo : RTM_ROUTE_INFO* in/out -> "sptr"
; TimeToLive : DWORD -> "sptr"
; RouteListHandle : INT_PTR -> "sptr"
; NotifyType : DWORD -> "sptr"
; NotifyHandle : INT_PTR -> "sptr"
; ChangeFlags : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "rtm.dll"
#cfunc global RtmAddRouteToDest "RtmAddRouteToDest" sptr, var, var, var, int, sptr, int, sptr, var
; res = RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
; RtmRegHandle : INT_PTR -> "sptr"
; RouteHandle : INT_PTR* in/out -> "var"
; DestAddress : RTM_NET_ADDRESS* in/out -> "var"
; RouteInfo : RTM_ROUTE_INFO* in/out -> "var"
; TimeToLive : DWORD -> "int"
; RouteListHandle : INT_PTR -> "sptr"
; NotifyType : DWORD -> "int"
; NotifyHandle : INT_PTR -> "sptr"
; ChangeFlags : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD RtmAddRouteToDest(INT_PTR RtmRegHandle, INT_PTR* RouteHandle, RTM_NET_ADDRESS* DestAddress, RTM_ROUTE_INFO* RouteInfo, DWORD TimeToLive, INT_PTR RouteListHandle, DWORD NotifyType, INT_PTR NotifyHandle, DWORD* ChangeFlags)
#uselib "rtm.dll"
#cfunc global RtmAddRouteToDest "RtmAddRouteToDest" intptr, var, var, var, int, intptr, int, intptr, var
; res = RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
; RtmRegHandle : INT_PTR -> "intptr"
; RouteHandle : INT_PTR* in/out -> "var"
; DestAddress : RTM_NET_ADDRESS* in/out -> "var"
; RouteInfo : RTM_ROUTE_INFO* in/out -> "var"
; TimeToLive : DWORD -> "int"
; RouteListHandle : INT_PTR -> "intptr"
; NotifyType : DWORD -> "int"
; NotifyHandle : INT_PTR -> "intptr"
; ChangeFlags : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	rtm = windows.NewLazySystemDLL("rtm.dll")
	procRtmAddRouteToDest = rtm.NewProc("RtmAddRouteToDest")
)

// RtmRegHandle (INT_PTR), RouteHandle (INT_PTR* in/out), DestAddress (RTM_NET_ADDRESS* in/out), RouteInfo (RTM_ROUTE_INFO* in/out), TimeToLive (DWORD), RouteListHandle (INT_PTR), NotifyType (DWORD), NotifyHandle (INT_PTR), ChangeFlags (DWORD* in/out)
r1, _, err := procRtmAddRouteToDest.Call(
	uintptr(RtmRegHandle),
	uintptr(RouteHandle),
	uintptr(DestAddress),
	uintptr(RouteInfo),
	uintptr(TimeToLive),
	uintptr(RouteListHandle),
	uintptr(NotifyType),
	uintptr(NotifyHandle),
	uintptr(ChangeFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RtmAddRouteToDest(
  RtmRegHandle: NativeInt;   // INT_PTR
  RouteHandle: Pointer;   // INT_PTR* in/out
  DestAddress: Pointer;   // RTM_NET_ADDRESS* in/out
  RouteInfo: Pointer;   // RTM_ROUTE_INFO* in/out
  TimeToLive: DWORD;   // DWORD
  RouteListHandle: NativeInt;   // INT_PTR
  NotifyType: DWORD;   // DWORD
  NotifyHandle: NativeInt;   // INT_PTR
  ChangeFlags: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'rtm.dll' name 'RtmAddRouteToDest';
result := DllCall("rtm\RtmAddRouteToDest"
    , "Ptr", RtmRegHandle   ; INT_PTR
    , "Ptr", RouteHandle   ; INT_PTR* in/out
    , "Ptr", DestAddress   ; RTM_NET_ADDRESS* in/out
    , "Ptr", RouteInfo   ; RTM_ROUTE_INFO* in/out
    , "UInt", TimeToLive   ; DWORD
    , "Ptr", RouteListHandle   ; INT_PTR
    , "UInt", NotifyType   ; DWORD
    , "Ptr", NotifyHandle   ; INT_PTR
    , "Ptr", ChangeFlags   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags) = DLL("rtm.dll", "dword RtmAddRouteToDest(int, void*, void*, void*, dword, int, dword, int, void*)")
# 呼び出し: RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
# RtmRegHandle : INT_PTR -> "int"
# RouteHandle : INT_PTR* in/out -> "void*"
# DestAddress : RTM_NET_ADDRESS* in/out -> "void*"
# RouteInfo : RTM_ROUTE_INFO* in/out -> "void*"
# TimeToLive : DWORD -> "dword"
# RouteListHandle : INT_PTR -> "int"
# NotifyType : DWORD -> "dword"
# NotifyHandle : INT_PTR -> "int"
# ChangeFlags : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "rtm" fn RtmAddRouteToDest(
    RtmRegHandle: isize, // INT_PTR
    RouteHandle: [*c]isize, // INT_PTR* in/out
    DestAddress: [*c]RTM_NET_ADDRESS, // RTM_NET_ADDRESS* in/out
    RouteInfo: [*c]RTM_ROUTE_INFO, // RTM_ROUTE_INFO* in/out
    TimeToLive: u32, // DWORD
    RouteListHandle: isize, // INT_PTR
    NotifyType: u32, // DWORD
    NotifyHandle: isize, // INT_PTR
    ChangeFlags: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc RtmAddRouteToDest(
    RtmRegHandle: int,  # INT_PTR
    RouteHandle: ptr int,  # INT_PTR* in/out
    DestAddress: ptr RTM_NET_ADDRESS,  # RTM_NET_ADDRESS* in/out
    RouteInfo: ptr RTM_ROUTE_INFO,  # RTM_ROUTE_INFO* in/out
    TimeToLive: uint32,  # DWORD
    RouteListHandle: int,  # INT_PTR
    NotifyType: uint32,  # DWORD
    NotifyHandle: int,  # INT_PTR
    ChangeFlags: ptr uint32  # DWORD* in/out
): uint32 {.importc: "RtmAddRouteToDest", stdcall, dynlib: "rtm.dll".}
pragma(lib, "rtm");
extern(Windows)
uint RtmAddRouteToDest(
    ptrdiff_t RtmRegHandle,   // INT_PTR
    ptrdiff_t* RouteHandle,   // INT_PTR* in/out
    RTM_NET_ADDRESS* DestAddress,   // RTM_NET_ADDRESS* in/out
    RTM_ROUTE_INFO* RouteInfo,   // RTM_ROUTE_INFO* in/out
    uint TimeToLive,   // DWORD
    ptrdiff_t RouteListHandle,   // INT_PTR
    uint NotifyType,   // DWORD
    ptrdiff_t NotifyHandle,   // INT_PTR
    uint* ChangeFlags   // DWORD* in/out
);
ccall((:RtmAddRouteToDest, "rtm.dll"), stdcall, UInt32,
      (Int, Ptr{Int}, Ptr{RTM_NET_ADDRESS}, Ptr{RTM_ROUTE_INFO}, UInt32, Int, UInt32, Int, Ptr{UInt32}),
      RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
# RtmRegHandle : INT_PTR -> Int
# RouteHandle : INT_PTR* in/out -> Ptr{Int}
# DestAddress : RTM_NET_ADDRESS* in/out -> Ptr{RTM_NET_ADDRESS}
# RouteInfo : RTM_ROUTE_INFO* in/out -> Ptr{RTM_ROUTE_INFO}
# TimeToLive : DWORD -> UInt32
# RouteListHandle : INT_PTR -> Int
# NotifyType : DWORD -> UInt32
# NotifyHandle : INT_PTR -> Int
# ChangeFlags : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RtmAddRouteToDest(
    intptr_t RtmRegHandle,
    intptr_t* RouteHandle,
    void* DestAddress,
    void* RouteInfo,
    uint32_t TimeToLive,
    intptr_t RouteListHandle,
    uint32_t NotifyType,
    intptr_t NotifyHandle,
    uint32_t* ChangeFlags);
]]
local rtm = ffi.load("rtm")
-- rtm.RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
-- RtmRegHandle : INT_PTR
-- RouteHandle : INT_PTR* in/out
-- DestAddress : RTM_NET_ADDRESS* in/out
-- RouteInfo : RTM_ROUTE_INFO* in/out
-- TimeToLive : DWORD
-- RouteListHandle : INT_PTR
-- NotifyType : DWORD
-- NotifyHandle : INT_PTR
-- ChangeFlags : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('rtm.dll');
const RtmAddRouteToDest = lib.func('__stdcall', 'RtmAddRouteToDest', 'uint32_t', ['intptr_t', 'intptr_t *', 'void *', 'void *', 'uint32_t', 'intptr_t', 'uint32_t', 'intptr_t', 'uint32_t *']);
// RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
// RtmRegHandle : INT_PTR -> 'intptr_t'
// RouteHandle : INT_PTR* in/out -> 'intptr_t *'
// DestAddress : RTM_NET_ADDRESS* in/out -> 'void *'
// RouteInfo : RTM_ROUTE_INFO* in/out -> 'void *'
// TimeToLive : DWORD -> 'uint32_t'
// RouteListHandle : INT_PTR -> 'intptr_t'
// NotifyType : DWORD -> 'uint32_t'
// NotifyHandle : INT_PTR -> 'intptr_t'
// ChangeFlags : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("rtm.dll", {
  RtmAddRouteToDest: { parameters: ["isize", "pointer", "pointer", "pointer", "u32", "isize", "u32", "isize", "pointer"], result: "u32" },
});
// lib.symbols.RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags)
// RtmRegHandle : INT_PTR -> "isize"
// RouteHandle : INT_PTR* in/out -> "pointer"
// DestAddress : RTM_NET_ADDRESS* in/out -> "pointer"
// RouteInfo : RTM_ROUTE_INFO* in/out -> "pointer"
// TimeToLive : DWORD -> "u32"
// RouteListHandle : INT_PTR -> "isize"
// NotifyType : DWORD -> "u32"
// NotifyHandle : INT_PTR -> "isize"
// ChangeFlags : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RtmAddRouteToDest(
    intptr_t RtmRegHandle,
    intptr_t* RouteHandle,
    void* DestAddress,
    void* RouteInfo,
    uint32_t TimeToLive,
    intptr_t RouteListHandle,
    uint32_t NotifyType,
    intptr_t NotifyHandle,
    uint32_t* ChangeFlags);
C, "rtm.dll");
// $ffi->RtmAddRouteToDest(RtmRegHandle, RouteHandle, DestAddress, RouteInfo, TimeToLive, RouteListHandle, NotifyType, NotifyHandle, ChangeFlags);
// RtmRegHandle : INT_PTR
// RouteHandle : INT_PTR* in/out
// DestAddress : RTM_NET_ADDRESS* in/out
// RouteInfo : RTM_ROUTE_INFO* in/out
// TimeToLive : DWORD
// RouteListHandle : INT_PTR
// NotifyType : DWORD
// NotifyHandle : INT_PTR
// ChangeFlags : DWORD* in/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 Rtm extends StdCallLibrary {
    Rtm INSTANCE = Native.load("rtm", Rtm.class);
    int RtmAddRouteToDest(
        long RtmRegHandle,   // INT_PTR
        LongByReference RouteHandle,   // INT_PTR* in/out
        Pointer DestAddress,   // RTM_NET_ADDRESS* in/out
        Pointer RouteInfo,   // RTM_ROUTE_INFO* in/out
        int TimeToLive,   // DWORD
        long RouteListHandle,   // INT_PTR
        int NotifyType,   // DWORD
        long NotifyHandle,   // INT_PTR
        IntByReference ChangeFlags   // DWORD* in/out
    );
}
@[Link("rtm")]
lib Librtm
  fun RtmAddRouteToDest = RtmAddRouteToDest(
    RtmRegHandle : LibC::SSizeT,   # INT_PTR
    RouteHandle : LibC::SSizeT*,   # INT_PTR* in/out
    DestAddress : RTM_NET_ADDRESS*,   # RTM_NET_ADDRESS* in/out
    RouteInfo : RTM_ROUTE_INFO*,   # RTM_ROUTE_INFO* in/out
    TimeToLive : UInt32,   # DWORD
    RouteListHandle : LibC::SSizeT,   # INT_PTR
    NotifyType : UInt32,   # DWORD
    NotifyHandle : LibC::SSizeT,   # INT_PTR
    ChangeFlags : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RtmAddRouteToDestNative = Uint32 Function(IntPtr, Pointer<IntPtr>, Pointer<Void>, Pointer<Void>, Uint32, IntPtr, Uint32, IntPtr, Pointer<Uint32>);
typedef RtmAddRouteToDestDart = int Function(int, Pointer<IntPtr>, Pointer<Void>, Pointer<Void>, int, int, int, int, Pointer<Uint32>);
final RtmAddRouteToDest = DynamicLibrary.open('rtm.dll')
    .lookupFunction<RtmAddRouteToDestNative, RtmAddRouteToDestDart>('RtmAddRouteToDest');
// RtmRegHandle : INT_PTR -> IntPtr
// RouteHandle : INT_PTR* in/out -> Pointer<IntPtr>
// DestAddress : RTM_NET_ADDRESS* in/out -> Pointer<Void>
// RouteInfo : RTM_ROUTE_INFO* in/out -> Pointer<Void>
// TimeToLive : DWORD -> Uint32
// RouteListHandle : INT_PTR -> IntPtr
// NotifyType : DWORD -> Uint32
// NotifyHandle : INT_PTR -> IntPtr
// ChangeFlags : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RtmAddRouteToDest(
  RtmRegHandle: NativeInt;   // INT_PTR
  RouteHandle: Pointer;   // INT_PTR* in/out
  DestAddress: Pointer;   // RTM_NET_ADDRESS* in/out
  RouteInfo: Pointer;   // RTM_ROUTE_INFO* in/out
  TimeToLive: DWORD;   // DWORD
  RouteListHandle: NativeInt;   // INT_PTR
  NotifyType: DWORD;   // DWORD
  NotifyHandle: NativeInt;   // INT_PTR
  ChangeFlags: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'rtm.dll' name 'RtmAddRouteToDest';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtmAddRouteToDest"
  c_RtmAddRouteToDest :: CIntPtr -> Ptr CIntPtr -> Ptr () -> Ptr () -> Word32 -> CIntPtr -> Word32 -> CIntPtr -> Ptr Word32 -> IO Word32
-- RtmRegHandle : INT_PTR -> CIntPtr
-- RouteHandle : INT_PTR* in/out -> Ptr CIntPtr
-- DestAddress : RTM_NET_ADDRESS* in/out -> Ptr ()
-- RouteInfo : RTM_ROUTE_INFO* in/out -> Ptr ()
-- TimeToLive : DWORD -> Word32
-- RouteListHandle : INT_PTR -> CIntPtr
-- NotifyType : DWORD -> Word32
-- NotifyHandle : INT_PTR -> CIntPtr
-- ChangeFlags : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtmaddroutetodest =
  foreign "RtmAddRouteToDest"
    (intptr_t @-> (ptr intptr_t) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> intptr_t @-> uint32_t @-> intptr_t @-> (ptr uint32_t) @-> returning uint32_t)
(* RtmRegHandle : INT_PTR -> intptr_t *)
(* RouteHandle : INT_PTR* in/out -> (ptr intptr_t) *)
(* DestAddress : RTM_NET_ADDRESS* in/out -> (ptr void) *)
(* RouteInfo : RTM_ROUTE_INFO* in/out -> (ptr void) *)
(* TimeToLive : DWORD -> uint32_t *)
(* RouteListHandle : INT_PTR -> intptr_t *)
(* NotifyType : DWORD -> uint32_t *)
(* NotifyHandle : INT_PTR -> intptr_t *)
(* ChangeFlags : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rtm (t "rtm.dll"))
(cffi:use-foreign-library rtm)

(cffi:defcfun ("RtmAddRouteToDest" rtm-add-route-to-dest :convention :stdcall) :uint32
  (rtm-reg-handle :int64)   ; INT_PTR
  (route-handle :pointer)   ; INT_PTR* in/out
  (dest-address :pointer)   ; RTM_NET_ADDRESS* in/out
  (route-info :pointer)   ; RTM_ROUTE_INFO* in/out
  (time-to-live :uint32)   ; DWORD
  (route-list-handle :int64)   ; INT_PTR
  (notify-type :uint32)   ; DWORD
  (notify-handle :int64)   ; INT_PTR
  (change-flags :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtmAddRouteToDest = Win32::API::More->new('rtm',
    'DWORD RtmAddRouteToDest(LPARAM RtmRegHandle, LPVOID RouteHandle, LPVOID DestAddress, LPVOID RouteInfo, DWORD TimeToLive, LPARAM RouteListHandle, DWORD NotifyType, LPARAM NotifyHandle, LPVOID ChangeFlags)');
# my $ret = $RtmAddRouteToDest->Call($RtmRegHandle, $RouteHandle, $DestAddress, $RouteInfo, $TimeToLive, $RouteListHandle, $NotifyType, $NotifyHandle, $ChangeFlags);
# RtmRegHandle : INT_PTR -> LPARAM
# RouteHandle : INT_PTR* in/out -> LPVOID
# DestAddress : RTM_NET_ADDRESS* in/out -> LPVOID
# RouteInfo : RTM_ROUTE_INFO* in/out -> LPVOID
# TimeToLive : DWORD -> DWORD
# RouteListHandle : INT_PTR -> LPARAM
# NotifyType : DWORD -> DWORD
# NotifyHandle : INT_PTR -> LPARAM
# ChangeFlags : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型