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

RasGetErrorStringW

関数
RASエラーコードに対応するエラーメッセージ文字列を取得する(Unicode版)。
DLLRASAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD RasGetErrorStringW(
    DWORD ResourceId,
    LPWSTR lpszString,
    DWORD InBufSize
);

パラメーター

名前方向
ResourceIdDWORDin
lpszStringLPWSTRout
InBufSizeDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RasGetErrorStringW(
    DWORD ResourceId,
    LPWSTR lpszString,
    DWORD InBufSize
);
[DllImport("RASAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RasGetErrorStringW(
    uint ResourceId,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszString,   // LPWSTR out
    uint InBufSize   // DWORD
);
<DllImport("RASAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RasGetErrorStringW(
    ResourceId As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszString As System.Text.StringBuilder,   ' LPWSTR out
    InBufSize As UInteger   ' DWORD
) As UInteger
End Function
' ResourceId : DWORD
' lpszString : LPWSTR out
' InBufSize : DWORD
Declare PtrSafe Function RasGetErrorStringW Lib "rasapi32" ( _
    ByVal ResourceId As Long, _
    ByVal lpszString As LongPtr, _
    ByVal InBufSize 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

RasGetErrorStringW = ctypes.windll.rasapi32.RasGetErrorStringW
RasGetErrorStringW.restype = wintypes.DWORD
RasGetErrorStringW.argtypes = [
    wintypes.DWORD,  # ResourceId : DWORD
    wintypes.LPWSTR,  # lpszString : LPWSTR out
    wintypes.DWORD,  # InBufSize : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	rasapi32 = windows.NewLazySystemDLL("RASAPI32.dll")
	procRasGetErrorStringW = rasapi32.NewProc("RasGetErrorStringW")
)

// ResourceId (DWORD), lpszString (LPWSTR out), InBufSize (DWORD)
r1, _, err := procRasGetErrorStringW.Call(
	uintptr(ResourceId),
	uintptr(lpszString),
	uintptr(InBufSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RasGetErrorStringW(
  ResourceId: DWORD;   // DWORD
  lpszString: PWideChar;   // LPWSTR out
  InBufSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'RASAPI32.dll' name 'RasGetErrorStringW';
result := DllCall("RASAPI32\RasGetErrorStringW"
    , "UInt", ResourceId   ; DWORD
    , "Ptr", lpszString   ; LPWSTR out
    , "UInt", InBufSize   ; DWORD
    , "UInt")   ; return: DWORD
●RasGetErrorStringW(ResourceId, lpszString, InBufSize) = DLL("RASAPI32.dll", "dword RasGetErrorStringW(dword, char*, dword)")
# 呼び出し: RasGetErrorStringW(ResourceId, lpszString, InBufSize)
# ResourceId : DWORD -> "dword"
# lpszString : LPWSTR out -> "char*"
# InBufSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。