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

RasSetCredentialsW

関数
RASエントリの認証資格情報を設定する(Unicode版)。
DLLRASAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// RASAPI32.dll  (Unicode / -W)
#include <windows.h>

DWORD RasSetCredentialsW(
    LPCWSTR param0,   // optional
    LPCWSTR param1,
    RASCREDENTIALSW* param2,
    BOOL param3
);

パラメーター

名前方向
param0LPCWSTRinoptional
param1LPCWSTRin
param2RASCREDENTIALSW*in
param3BOOLin

戻り値の型: DWORD

各言語での呼び出し定義

// RASAPI32.dll  (Unicode / -W)
#include <windows.h>

DWORD RasSetCredentialsW(
    LPCWSTR param0,   // optional
    LPCWSTR param1,
    RASCREDENTIALSW* param2,
    BOOL param3
);
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RasSetCredentialsW(
    [MarshalAs(UnmanagedType.LPWStr)] string param0,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string param1,   // LPCWSTR
    IntPtr param2,   // RASCREDENTIALSW*
    bool param3   // BOOL
);
<DllImport("RASAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RasSetCredentialsW(
    <MarshalAs(UnmanagedType.LPWStr)> param0 As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> param1 As String,   ' LPCWSTR
    param2 As IntPtr,   ' RASCREDENTIALSW*
    param3 As Boolean   ' BOOL
) As UInteger
End Function
' param0 : LPCWSTR optional
' param1 : LPCWSTR
' param2 : RASCREDENTIALSW*
' param3 : BOOL
Declare PtrSafe Function RasSetCredentialsW Lib "rasapi32" ( _
    ByVal param0 As LongPtr, _
    ByVal param1 As LongPtr, _
    ByVal param2 As LongPtr, _
    ByVal param3 As Long) 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

RasSetCredentialsW = ctypes.windll.rasapi32.RasSetCredentialsW
RasSetCredentialsW.restype = wintypes.DWORD
RasSetCredentialsW.argtypes = [
    wintypes.LPCWSTR,  # param0 : LPCWSTR optional
    wintypes.LPCWSTR,  # param1 : LPCWSTR
    ctypes.c_void_p,  # param2 : RASCREDENTIALSW*
    wintypes.BOOL,  # param3 : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('RASAPI32.dll')
RasSetCredentialsW = Fiddle::Function.new(
  lib['RasSetCredentialsW'],
  [
    Fiddle::TYPE_VOIDP,  # param0 : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # param1 : LPCWSTR
    Fiddle::TYPE_VOIDP,  # param2 : RASCREDENTIALSW*
    Fiddle::TYPE_INT,  # param3 : BOOL
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "rasapi32")]
extern "system" {
    fn RasSetCredentialsW(
        param0: *const u16,  // LPCWSTR optional
        param1: *const u16,  // LPCWSTR
        param2: *mut RASCREDENTIALSW,  // RASCREDENTIALSW*
        param3: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RasSetCredentialsW([MarshalAs(UnmanagedType.LPWStr)] string param0, [MarshalAs(UnmanagedType.LPWStr)] string param1, IntPtr param2, bool param3);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RASAPI32_RasSetCredentialsW' -Namespace Win32 -PassThru
# $api::RasSetCredentialsW(param0, param1, param2, param3)
#uselib "RASAPI32.dll"
#func global RasSetCredentialsW "RasSetCredentialsW" wptr, wptr, wptr, wptr
; RasSetCredentialsW param0, param1, varptr(param2), param3   ; 戻り値は stat
; param0 : LPCWSTR optional -> "wptr"
; param1 : LPCWSTR -> "wptr"
; param2 : RASCREDENTIALSW* -> "wptr"
; param3 : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "RASAPI32.dll"
#cfunc global RasSetCredentialsW "RasSetCredentialsW" wstr, wstr, var, int
; res = RasSetCredentialsW(param0, param1, param2, param3)
; param0 : LPCWSTR optional -> "wstr"
; param1 : LPCWSTR -> "wstr"
; param2 : RASCREDENTIALSW* -> "var"
; param3 : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD RasSetCredentialsW(LPCWSTR param0, LPCWSTR param1, RASCREDENTIALSW* param2, BOOL param3)
#uselib "RASAPI32.dll"
#cfunc global RasSetCredentialsW "RasSetCredentialsW" wstr, wstr, var, int
; res = RasSetCredentialsW(param0, param1, param2, param3)
; param0 : LPCWSTR optional -> "wstr"
; param1 : LPCWSTR -> "wstr"
; param2 : RASCREDENTIALSW* -> "var"
; param3 : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	rasapi32 = windows.NewLazySystemDLL("RASAPI32.dll")
	procRasSetCredentialsW = rasapi32.NewProc("RasSetCredentialsW")
)

// param0 (LPCWSTR optional), param1 (LPCWSTR), param2 (RASCREDENTIALSW*), param3 (BOOL)
r1, _, err := procRasSetCredentialsW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param0))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(param1))),
	uintptr(param2),
	uintptr(param3),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RasSetCredentialsW(
  param0: PWideChar;   // LPCWSTR optional
  param1: PWideChar;   // LPCWSTR
  param2: Pointer;   // RASCREDENTIALSW*
  param3: BOOL   // BOOL
): DWORD; stdcall;
  external 'RASAPI32.dll' name 'RasSetCredentialsW';
result := DllCall("RASAPI32\RasSetCredentialsW"
    , "WStr", param0   ; LPCWSTR optional
    , "WStr", param1   ; LPCWSTR
    , "Ptr", param2   ; RASCREDENTIALSW*
    , "Int", param3   ; BOOL
    , "UInt")   ; return: DWORD
●RasSetCredentialsW(param0, param1, param2, param3) = DLL("RASAPI32.dll", "dword RasSetCredentialsW(char*, char*, void*, bool)")
# 呼び出し: RasSetCredentialsW(param0, param1, param2, param3)
# param0 : LPCWSTR optional -> "char*"
# param1 : LPCWSTR -> "char*"
# param2 : RASCREDENTIALSW* -> "void*"
# param3 : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。