ホーム › NetworkManagement.Rras › RasDialW
RasDialW
関数RAS接続(ダイヤルアップ/VPN)を確立する(Unicode版)。
シグネチャ
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasDialW(
RASDIALEXTENSIONS* param0, // optional
LPCWSTR param1, // optional
RASDIALPARAMSW* param2,
DWORD param3,
void* param4, // optional
HRASCONN* param5
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| param0 | RASDIALEXTENSIONS* | inoptional | ダイヤル拡張オプションを格納したRASDIALEXTENSIONS構造体へのポインタ。NULL可。 |
| param1 | LPCWSTR | inoptional | 使用する電話帳ファイルのパスを指すワイド文字列。NULLで既定の電話帳を使う。 |
| param2 | RASDIALPARAMSW* | in | 接続エントリ名や認証情報を格納したRASDIALPARAMSW構造体へのポインタ。 |
| param3 | DWORD | in | 通知の種類を示す値。RASDIALFUNC等の解釈に影響する。 |
| param4 | void* | inoptional | 進捗通知を受け取るウィンドウハンドルまたはコールバック関数へのポインタ。NULL可。 |
| param5 | HRASCONN* | out | 確立されたRAS接続のハンドルを受け取るポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasDialW(
RASDIALEXTENSIONS* param0, // optional
LPCWSTR param1, // optional
RASDIALPARAMSW* param2,
DWORD param3,
void* param4, // optional
HRASCONN* param5
);[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RasDialW(
IntPtr param0, // RASDIALEXTENSIONS* optional
[MarshalAs(UnmanagedType.LPWStr)] string param1, // LPCWSTR optional
IntPtr param2, // RASDIALPARAMSW*
uint param3, // DWORD
IntPtr param4, // void* optional
IntPtr param5 // HRASCONN* out
);<DllImport("RASAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RasDialW(
param0 As IntPtr, ' RASDIALEXTENSIONS* optional
<MarshalAs(UnmanagedType.LPWStr)> param1 As String, ' LPCWSTR optional
param2 As IntPtr, ' RASDIALPARAMSW*
param3 As UInteger, ' DWORD
param4 As IntPtr, ' void* optional
param5 As IntPtr ' HRASCONN* out
) As UInteger
End Function' param0 : RASDIALEXTENSIONS* optional
' param1 : LPCWSTR optional
' param2 : RASDIALPARAMSW*
' param3 : DWORD
' param4 : void* optional
' param5 : HRASCONN* out
Declare PtrSafe Function RasDialW Lib "rasapi32" ( _
ByVal param0 As LongPtr, _
ByVal param1 As LongPtr, _
ByVal param2 As LongPtr, _
ByVal param3 As Long, _
ByVal param4 As LongPtr, _
ByVal param5 As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RasDialW = ctypes.windll.rasapi32.RasDialW
RasDialW.restype = wintypes.DWORD
RasDialW.argtypes = [
ctypes.c_void_p, # param0 : RASDIALEXTENSIONS* optional
wintypes.LPCWSTR, # param1 : LPCWSTR optional
ctypes.c_void_p, # param2 : RASDIALPARAMSW*
wintypes.DWORD, # param3 : DWORD
ctypes.POINTER(None), # param4 : void* optional
ctypes.c_void_p, # param5 : HRASCONN* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RASAPI32.dll')
RasDialW = Fiddle::Function.new(
lib['RasDialW'],
[
Fiddle::TYPE_VOIDP, # param0 : RASDIALEXTENSIONS* optional
Fiddle::TYPE_VOIDP, # param1 : LPCWSTR optional
Fiddle::TYPE_VOIDP, # param2 : RASDIALPARAMSW*
-Fiddle::TYPE_INT, # param3 : DWORD
Fiddle::TYPE_VOIDP, # param4 : void* optional
Fiddle::TYPE_VOIDP, # param5 : HRASCONN* out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rasapi32")]
extern "system" {
fn RasDialW(
param0: *mut RASDIALEXTENSIONS, // RASDIALEXTENSIONS* optional
param1: *const u16, // LPCWSTR optional
param2: *mut RASDIALPARAMSW, // RASDIALPARAMSW*
param3: u32, // DWORD
param4: *mut (), // void* optional
param5: *mut *mut core::ffi::c_void // HRASCONN* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RasDialW(IntPtr param0, [MarshalAs(UnmanagedType.LPWStr)] string param1, IntPtr param2, uint param3, IntPtr param4, IntPtr param5);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RASAPI32_RasDialW' -Namespace Win32 -PassThru
# $api::RasDialW(param0, param1, param2, param3, param4, param5)#uselib "RASAPI32.dll"
#func global RasDialW "RasDialW" wptr, wptr, wptr, wptr, wptr, wptr
; RasDialW varptr(param0), param1, varptr(param2), param3, param4, param5 ; 戻り値は stat
; param0 : RASDIALEXTENSIONS* optional -> "wptr"
; param1 : LPCWSTR optional -> "wptr"
; param2 : RASDIALPARAMSW* -> "wptr"
; param3 : DWORD -> "wptr"
; param4 : void* optional -> "wptr"
; param5 : HRASCONN* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "RASAPI32.dll" #cfunc global RasDialW "RasDialW" var, wstr, var, int, sptr, sptr ; res = RasDialW(param0, param1, param2, param3, param4, param5) ; param0 : RASDIALEXTENSIONS* optional -> "var" ; param1 : LPCWSTR optional -> "wstr" ; param2 : RASDIALPARAMSW* -> "var" ; param3 : DWORD -> "int" ; param4 : void* optional -> "sptr" ; param5 : HRASCONN* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "RASAPI32.dll" #cfunc global RasDialW "RasDialW" sptr, wstr, sptr, int, sptr, sptr ; res = RasDialW(varptr(param0), param1, varptr(param2), param3, param4, param5) ; param0 : RASDIALEXTENSIONS* optional -> "sptr" ; param1 : LPCWSTR optional -> "wstr" ; param2 : RASDIALPARAMSW* -> "sptr" ; param3 : DWORD -> "int" ; param4 : void* optional -> "sptr" ; param5 : HRASCONN* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD RasDialW(RASDIALEXTENSIONS* param0, LPCWSTR param1, RASDIALPARAMSW* param2, DWORD param3, void* param4, HRASCONN* param5) #uselib "RASAPI32.dll" #cfunc global RasDialW "RasDialW" var, wstr, var, int, intptr, intptr ; res = RasDialW(param0, param1, param2, param3, param4, param5) ; param0 : RASDIALEXTENSIONS* optional -> "var" ; param1 : LPCWSTR optional -> "wstr" ; param2 : RASDIALPARAMSW* -> "var" ; param3 : DWORD -> "int" ; param4 : void* optional -> "intptr" ; param5 : HRASCONN* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD RasDialW(RASDIALEXTENSIONS* param0, LPCWSTR param1, RASDIALPARAMSW* param2, DWORD param3, void* param4, HRASCONN* param5) #uselib "RASAPI32.dll" #cfunc global RasDialW "RasDialW" intptr, wstr, intptr, int, intptr, intptr ; res = RasDialW(varptr(param0), param1, varptr(param2), param3, param4, param5) ; param0 : RASDIALEXTENSIONS* optional -> "intptr" ; param1 : LPCWSTR optional -> "wstr" ; param2 : RASDIALPARAMSW* -> "intptr" ; param3 : DWORD -> "int" ; param4 : void* optional -> "intptr" ; param5 : HRASCONN* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rasapi32 = windows.NewLazySystemDLL("RASAPI32.dll")
procRasDialW = rasapi32.NewProc("RasDialW")
)
// param0 (RASDIALEXTENSIONS* optional), param1 (LPCWSTR optional), param2 (RASDIALPARAMSW*), param3 (DWORD), param4 (void* optional), param5 (HRASCONN* out)
r1, _, err := procRasDialW.Call(
uintptr(param0),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param1))),
uintptr(param2),
uintptr(param3),
uintptr(param4),
uintptr(param5),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RasDialW(
param0: Pointer; // RASDIALEXTENSIONS* optional
param1: PWideChar; // LPCWSTR optional
param2: Pointer; // RASDIALPARAMSW*
param3: DWORD; // DWORD
param4: Pointer; // void* optional
param5: Pointer // HRASCONN* out
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasDialW';result := DllCall("RASAPI32\RasDialW"
, "Ptr", param0 ; RASDIALEXTENSIONS* optional
, "WStr", param1 ; LPCWSTR optional
, "Ptr", param2 ; RASDIALPARAMSW*
, "UInt", param3 ; DWORD
, "Ptr", param4 ; void* optional
, "Ptr", param5 ; HRASCONN* out
, "UInt") ; return: DWORD●RasDialW(param0, param1, param2, param3, param4, param5) = DLL("RASAPI32.dll", "dword RasDialW(void*, char*, void*, dword, void*, void*)")
# 呼び出し: RasDialW(param0, param1, param2, param3, param4, param5)
# param0 : RASDIALEXTENSIONS* optional -> "void*"
# param1 : LPCWSTR optional -> "char*"
# param2 : RASDIALPARAMSW* -> "void*"
# param3 : DWORD -> "dword"
# param4 : void* optional -> "void*"
# param5 : HRASCONN* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rasapi32" fn RasDialW(
param0: [*c]RASDIALEXTENSIONS, // RASDIALEXTENSIONS* optional
param1: [*c]const u16, // LPCWSTR optional
param2: [*c]RASDIALPARAMSW, // RASDIALPARAMSW*
param3: u32, // DWORD
param4: ?*anyopaque, // void* optional
param5: ?*anyopaque // HRASCONN* out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RasDialW(
param0: ptr RASDIALEXTENSIONS, # RASDIALEXTENSIONS* optional
param1: WideCString, # LPCWSTR optional
param2: ptr RASDIALPARAMSW, # RASDIALPARAMSW*
param3: uint32, # DWORD
param4: pointer, # void* optional
param5: pointer # HRASCONN* out
): uint32 {.importc: "RasDialW", stdcall, dynlib: "RASAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rasapi32");
extern(Windows)
uint RasDialW(
RASDIALEXTENSIONS* param0, // RASDIALEXTENSIONS* optional
const(wchar)* param1, // LPCWSTR optional
RASDIALPARAMSW* param2, // RASDIALPARAMSW*
uint param3, // DWORD
void* param4, // void* optional
void* param5 // HRASCONN* out
);ccall((:RasDialW, "RASAPI32.dll"), stdcall, UInt32,
(Ptr{RASDIALEXTENSIONS}, Cwstring, Ptr{RASDIALPARAMSW}, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
param0, param1, param2, param3, param4, param5)
# param0 : RASDIALEXTENSIONS* optional -> Ptr{RASDIALEXTENSIONS}
# param1 : LPCWSTR optional -> Cwstring
# param2 : RASDIALPARAMSW* -> Ptr{RASDIALPARAMSW}
# param3 : DWORD -> UInt32
# param4 : void* optional -> Ptr{Cvoid}
# param5 : HRASCONN* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RasDialW(
void* param0,
const uint16_t* param1,
void* param2,
uint32_t param3,
void* param4,
void* param5);
]]
local rasapi32 = ffi.load("rasapi32")
-- rasapi32.RasDialW(param0, param1, param2, param3, param4, param5)
-- param0 : RASDIALEXTENSIONS* optional
-- param1 : LPCWSTR optional
-- param2 : RASDIALPARAMSW*
-- param3 : DWORD
-- param4 : void* optional
-- param5 : HRASCONN* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('RASAPI32.dll');
const RasDialW = lib.func('__stdcall', 'RasDialW', 'uint32_t', ['void *', 'str16', 'void *', 'uint32_t', 'void *', 'void *']);
// RasDialW(param0, param1, param2, param3, param4, param5)
// param0 : RASDIALEXTENSIONS* optional -> 'void *'
// param1 : LPCWSTR optional -> 'str16'
// param2 : RASDIALPARAMSW* -> 'void *'
// param3 : DWORD -> 'uint32_t'
// param4 : void* optional -> 'void *'
// param5 : HRASCONN* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RASAPI32.dll", {
RasDialW: { parameters: ["pointer", "buffer", "pointer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.RasDialW(param0, param1, param2, param3, param4, param5)
// param0 : RASDIALEXTENSIONS* optional -> "pointer"
// param1 : LPCWSTR optional -> "buffer"
// param2 : RASDIALPARAMSW* -> "pointer"
// param3 : DWORD -> "u32"
// param4 : void* optional -> "pointer"
// param5 : HRASCONN* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RasDialW(
void* param0,
const uint16_t* param1,
void* param2,
uint32_t param3,
void* param4,
void* param5);
C, "RASAPI32.dll");
// $ffi->RasDialW(param0, param1, param2, param3, param4, param5);
// param0 : RASDIALEXTENSIONS* optional
// param1 : LPCWSTR optional
// param2 : RASDIALPARAMSW*
// param3 : DWORD
// param4 : void* optional
// param5 : HRASCONN* 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 Rasapi32 extends StdCallLibrary {
Rasapi32 INSTANCE = Native.load("rasapi32", Rasapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RasDialW(
Pointer param0, // RASDIALEXTENSIONS* optional
WString param1, // LPCWSTR optional
Pointer param2, // RASDIALPARAMSW*
int param3, // DWORD
Pointer param4, // void* optional
Pointer param5 // HRASCONN* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rasapi32")]
lib LibRASAPI32
fun RasDialW = RasDialW(
param0 : RASDIALEXTENSIONS*, # RASDIALEXTENSIONS* optional
param1 : UInt16*, # LPCWSTR optional
param2 : RASDIALPARAMSW*, # RASDIALPARAMSW*
param3 : UInt32, # DWORD
param4 : Void*, # void* optional
param5 : Void* # HRASCONN* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RasDialWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef RasDialWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final RasDialW = DynamicLibrary.open('RASAPI32.dll')
.lookupFunction<RasDialWNative, RasDialWDart>('RasDialW');
// param0 : RASDIALEXTENSIONS* optional -> Pointer<Void>
// param1 : LPCWSTR optional -> Pointer<Utf16>
// param2 : RASDIALPARAMSW* -> Pointer<Void>
// param3 : DWORD -> Uint32
// param4 : void* optional -> Pointer<Void>
// param5 : HRASCONN* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RasDialW(
param0: Pointer; // RASDIALEXTENSIONS* optional
param1: PWideChar; // LPCWSTR optional
param2: Pointer; // RASDIALPARAMSW*
param3: DWORD; // DWORD
param4: Pointer; // void* optional
param5: Pointer // HRASCONN* out
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasDialW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RasDialW"
c_RasDialW :: Ptr () -> CWString -> Ptr () -> Word32 -> Ptr () -> Ptr () -> IO Word32
-- param0 : RASDIALEXTENSIONS* optional -> Ptr ()
-- param1 : LPCWSTR optional -> CWString
-- param2 : RASDIALPARAMSW* -> Ptr ()
-- param3 : DWORD -> Word32
-- param4 : void* optional -> Ptr ()
-- param5 : HRASCONN* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rasdialw =
foreign "RasDialW"
((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* param0 : RASDIALEXTENSIONS* optional -> (ptr void) *)
(* param1 : LPCWSTR optional -> (ptr uint16_t) *)
(* param2 : RASDIALPARAMSW* -> (ptr void) *)
(* param3 : DWORD -> uint32_t *)
(* param4 : void* optional -> (ptr void) *)
(* param5 : HRASCONN* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rasapi32 (t "RASAPI32.dll"))
(cffi:use-foreign-library rasapi32)
(cffi:defcfun ("RasDialW" ras-dial-w :convention :stdcall) :uint32
(param0 :pointer) ; RASDIALEXTENSIONS* optional
(param1 (:string :encoding :utf-16le)) ; LPCWSTR optional
(param2 :pointer) ; RASDIALPARAMSW*
(param3 :uint32) ; DWORD
(param4 :pointer) ; void* optional
(param5 :pointer)) ; HRASCONN* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RasDialW = Win32::API::More->new('RASAPI32',
'DWORD RasDialW(LPVOID param0, LPCWSTR param1, LPVOID param2, DWORD param3, LPVOID param4, HANDLE param5)');
# my $ret = $RasDialW->Call($param0, $param1, $param2, $param3, $param4, $param5);
# param0 : RASDIALEXTENSIONS* optional -> LPVOID
# param1 : LPCWSTR optional -> LPCWSTR
# param2 : RASDIALPARAMSW* -> LPVOID
# param3 : DWORD -> DWORD
# param4 : void* optional -> LPVOID
# param5 : HRASCONN* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RasDialA (ANSI版) — RAS接続(ダイヤルアップ/VPN)を確立する(ANSI版)。