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電話帳ファイルのフルパス文字列。NULL指定で既定の電話帳を使用する。
param1LPCWSTRin資格情報を設定する対象エントリ名の文字列。
param2RASCREDENTIALSW*in設定する資格情報を格納したRASCREDENTIALSW構造体へのポインタ。dwMaskで設定項目を指定する。
param3BOOLinTRUEで指定資格情報を消去、FALSEで設定する真偽値。

戻り値の型: 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 版の利用を推奨。
const std = @import("std");

extern "rasapi32" fn RasSetCredentialsW(
    param0: [*c]const u16, // LPCWSTR optional
    param1: [*c]const u16, // LPCWSTR
    param2: [*c]RASCREDENTIALSW, // RASCREDENTIALSW*
    param3: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc RasSetCredentialsW(
    param0: WideCString,  # LPCWSTR optional
    param1: WideCString,  # LPCWSTR
    param2: ptr RASCREDENTIALSW,  # RASCREDENTIALSW*
    param3: int32  # BOOL
): uint32 {.importc: "RasSetCredentialsW", stdcall, dynlib: "RASAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "rasapi32");
extern(Windows)
uint RasSetCredentialsW(
    const(wchar)* param0,   // LPCWSTR optional
    const(wchar)* param1,   // LPCWSTR
    RASCREDENTIALSW* param2,   // RASCREDENTIALSW*
    int param3   // BOOL
);
ccall((:RasSetCredentialsW, "RASAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Ptr{RASCREDENTIALSW}, Int32),
      param0, param1, param2, param3)
# param0 : LPCWSTR optional -> Cwstring
# param1 : LPCWSTR -> Cwstring
# param2 : RASCREDENTIALSW* -> Ptr{RASCREDENTIALSW}
# param3 : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RasSetCredentialsW(
    const uint16_t* param0,
    const uint16_t* param1,
    void* param2,
    int32_t param3);
]]
local rasapi32 = ffi.load("rasapi32")
-- rasapi32.RasSetCredentialsW(param0, param1, param2, param3)
-- param0 : LPCWSTR optional
-- param1 : LPCWSTR
-- param2 : RASCREDENTIALSW*
-- param3 : BOOL
-- 構造体/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 RasSetCredentialsW = lib.func('__stdcall', 'RasSetCredentialsW', 'uint32_t', ['str16', 'str16', 'void *', 'int32_t']);
// RasSetCredentialsW(param0, param1, param2, param3)
// param0 : LPCWSTR optional -> 'str16'
// param1 : LPCWSTR -> 'str16'
// param2 : RASCREDENTIALSW* -> 'void *'
// param3 : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("RASAPI32.dll", {
  RasSetCredentialsW: { parameters: ["buffer", "buffer", "pointer", "i32"], result: "u32" },
});
// lib.symbols.RasSetCredentialsW(param0, param1, param2, param3)
// param0 : LPCWSTR optional -> "buffer"
// param1 : LPCWSTR -> "buffer"
// param2 : RASCREDENTIALSW* -> "pointer"
// param3 : BOOL -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RasSetCredentialsW(
    const uint16_t* param0,
    const uint16_t* param1,
    void* param2,
    int32_t param3);
C, "RASAPI32.dll");
// $ffi->RasSetCredentialsW(param0, param1, param2, param3);
// param0 : LPCWSTR optional
// param1 : LPCWSTR
// param2 : RASCREDENTIALSW*
// param3 : BOOL
// 構造体/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 RasSetCredentialsW(
        WString param0,   // LPCWSTR optional
        WString param1,   // LPCWSTR
        Pointer param2,   // RASCREDENTIALSW*
        boolean param3   // BOOL
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("rasapi32")]
lib LibRASAPI32
  fun RasSetCredentialsW = RasSetCredentialsW(
    param0 : UInt16*,   # LPCWSTR optional
    param1 : UInt16*,   # LPCWSTR
    param2 : RASCREDENTIALSW*,   # RASCREDENTIALSW*
    param3 : Int32   # BOOL
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RasSetCredentialsWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Int32);
typedef RasSetCredentialsWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, int);
final RasSetCredentialsW = DynamicLibrary.open('RASAPI32.dll')
    .lookupFunction<RasSetCredentialsWNative, RasSetCredentialsWDart>('RasSetCredentialsW');
// param0 : LPCWSTR optional -> Pointer<Utf16>
// param1 : LPCWSTR -> Pointer<Utf16>
// param2 : RASCREDENTIALSW* -> Pointer<Void>
// param3 : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RasSetCredentialsW(
  param0: PWideChar;   // LPCWSTR optional
  param1: PWideChar;   // LPCWSTR
  param2: Pointer;   // RASCREDENTIALSW*
  param3: BOOL   // BOOL
): DWORD; stdcall;
  external 'RASAPI32.dll' name 'RasSetCredentialsW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RasSetCredentialsW"
  c_RasSetCredentialsW :: CWString -> CWString -> Ptr () -> CInt -> IO Word32
-- param0 : LPCWSTR optional -> CWString
-- param1 : LPCWSTR -> CWString
-- param2 : RASCREDENTIALSW* -> Ptr ()
-- param3 : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rassetcredentialsw =
  foreign "RasSetCredentialsW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> int32_t @-> returning uint32_t)
(* param0 : LPCWSTR optional -> (ptr uint16_t) *)
(* param1 : LPCWSTR -> (ptr uint16_t) *)
(* param2 : RASCREDENTIALSW* -> (ptr void) *)
(* param3 : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rasapi32 (t "RASAPI32.dll"))
(cffi:use-foreign-library rasapi32)

(cffi:defcfun ("RasSetCredentialsW" ras-set-credentials-w :convention :stdcall) :uint32
  (param0 (:string :encoding :utf-16le))   ; LPCWSTR optional
  (param1 (:string :encoding :utf-16le))   ; LPCWSTR
  (param2 :pointer)   ; RASCREDENTIALSW*
  (param3 :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RasSetCredentialsW = Win32::API::More->new('RASAPI32',
    'DWORD RasSetCredentialsW(LPCWSTR param0, LPCWSTR param1, LPVOID param2, BOOL param3)');
# my $ret = $RasSetCredentialsW->Call($param0, $param1, $param2, $param3);
# param0 : LPCWSTR optional -> LPCWSTR
# param1 : LPCWSTR -> LPCWSTR
# param2 : RASCREDENTIALSW* -> LPVOID
# param3 : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型