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_PTRin
RouteHandleINT_PTR*inout
DestAddressRTM_NET_ADDRESS*inout
RouteInfoRTM_ROUTE_INFO*inout
TimeToLiveDWORDin
RouteListHandleINT_PTRin
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)。