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

OnDemandGetRoutingHint

関数
宛先ホスト名に最適なインターフェイスのルーティングヒントを取得する。
DLLOnDemandConnRouteHelper.dll呼出規約winapi対応OSWindows 8.1 以降

シグネチャ

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

HRESULT OnDemandGetRoutingHint(
    LPCWSTR destinationHostName,
    DWORD* interfaceIndex
);

パラメーター

名前方向
destinationHostNameLPCWSTRin
interfaceIndexDWORD*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT OnDemandGetRoutingHint(
    LPCWSTR destinationHostName,
    DWORD* interfaceIndex
);
[DllImport("OnDemandConnRouteHelper.dll", ExactSpelling = true)]
static extern int OnDemandGetRoutingHint(
    [MarshalAs(UnmanagedType.LPWStr)] string destinationHostName,   // LPCWSTR
    out uint interfaceIndex   // DWORD* out
);
<DllImport("OnDemandConnRouteHelper.dll", ExactSpelling:=True)>
Public Shared Function OnDemandGetRoutingHint(
    <MarshalAs(UnmanagedType.LPWStr)> destinationHostName As String,   ' LPCWSTR
    <Out> ByRef interfaceIndex As UInteger   ' DWORD* out
) As Integer
End Function
' destinationHostName : LPCWSTR
' interfaceIndex : DWORD* out
Declare PtrSafe Function OnDemandGetRoutingHint Lib "ondemandconnroutehelper" ( _
    ByVal destinationHostName As LongPtr, _
    ByRef interfaceIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

OnDemandGetRoutingHint = ctypes.windll.ondemandconnroutehelper.OnDemandGetRoutingHint
OnDemandGetRoutingHint.restype = ctypes.c_int
OnDemandGetRoutingHint.argtypes = [
    wintypes.LPCWSTR,  # destinationHostName : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # interfaceIndex : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OnDemandConnRouteHelper.dll')
OnDemandGetRoutingHint = Fiddle::Function.new(
  lib['OnDemandGetRoutingHint'],
  [
    Fiddle::TYPE_VOIDP,  # destinationHostName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # interfaceIndex : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ondemandconnroutehelper")]
extern "system" {
    fn OnDemandGetRoutingHint(
        destinationHostName: *const u16,  // LPCWSTR
        interfaceIndex: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OnDemandConnRouteHelper.dll")]
public static extern int OnDemandGetRoutingHint([MarshalAs(UnmanagedType.LPWStr)] string destinationHostName, out uint interfaceIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OnDemandConnRouteHelper_OnDemandGetRoutingHint' -Namespace Win32 -PassThru
# $api::OnDemandGetRoutingHint(destinationHostName, interfaceIndex)
#uselib "OnDemandConnRouteHelper.dll"
#func global OnDemandGetRoutingHint "OnDemandGetRoutingHint" sptr, sptr
; OnDemandGetRoutingHint destinationHostName, varptr(interfaceIndex)   ; 戻り値は stat
; destinationHostName : LPCWSTR -> "sptr"
; interfaceIndex : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OnDemandConnRouteHelper.dll"
#cfunc global OnDemandGetRoutingHint "OnDemandGetRoutingHint" wstr, var
; res = OnDemandGetRoutingHint(destinationHostName, interfaceIndex)
; destinationHostName : LPCWSTR -> "wstr"
; interfaceIndex : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT OnDemandGetRoutingHint(LPCWSTR destinationHostName, DWORD* interfaceIndex)
#uselib "OnDemandConnRouteHelper.dll"
#cfunc global OnDemandGetRoutingHint "OnDemandGetRoutingHint" wstr, var
; res = OnDemandGetRoutingHint(destinationHostName, interfaceIndex)
; destinationHostName : LPCWSTR -> "wstr"
; interfaceIndex : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ondemandconnroutehelper = windows.NewLazySystemDLL("OnDemandConnRouteHelper.dll")
	procOnDemandGetRoutingHint = ondemandconnroutehelper.NewProc("OnDemandGetRoutingHint")
)

// destinationHostName (LPCWSTR), interfaceIndex (DWORD* out)
r1, _, err := procOnDemandGetRoutingHint.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(destinationHostName))),
	uintptr(interfaceIndex),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function OnDemandGetRoutingHint(
  destinationHostName: PWideChar;   // LPCWSTR
  interfaceIndex: Pointer   // DWORD* out
): Integer; stdcall;
  external 'OnDemandConnRouteHelper.dll' name 'OnDemandGetRoutingHint';
result := DllCall("OnDemandConnRouteHelper\OnDemandGetRoutingHint"
    , "WStr", destinationHostName   ; LPCWSTR
    , "Ptr", interfaceIndex   ; DWORD* out
    , "Int")   ; return: HRESULT
●OnDemandGetRoutingHint(destinationHostName, interfaceIndex) = DLL("OnDemandConnRouteHelper.dll", "int OnDemandGetRoutingHint(char*, void*)")
# 呼び出し: OnDemandGetRoutingHint(destinationHostName, interfaceIndex)
# destinationHostName : LPCWSTR -> "char*"
# interfaceIndex : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。