ホーム › NetworkManagement.Rras › RasGetErrorStringW
RasGetErrorStringW
関数RASエラーコードに対応するエラーメッセージ文字列を取得する(Unicode版)。
シグネチャ
// RASAPI32.dll (Unicode / -W)
#include <windows.h>
DWORD RasGetErrorStringW(
DWORD ResourceId,
LPWSTR lpszString,
DWORD InBufSize
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ResourceId | DWORD | in | メッセージを取得するRAS固有のエラーコード値。 |
| lpszString | LPWSTR | out | エラーメッセージ文字列を受け取るワイドバッファへのポインタ。 |
| InBufSize | DWORD | in | lpszStringが指すバッファの文字数。 |
戻り値の型: 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 方式にも切替可。#uselib "RASAPI32.dll" #cfunc global RasGetErrorStringW "RasGetErrorStringW" int, sptr, int ; res = RasGetErrorStringW(ResourceId, varptr(lpszString), InBufSize) ; ResourceId : DWORD -> "int" ; lpszString : LPWSTR out -> "sptr" ; InBufSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; DWORD RasGetErrorStringW(DWORD ResourceId, LPWSTR lpszString, DWORD InBufSize) #uselib "RASAPI32.dll" #cfunc global RasGetErrorStringW "RasGetErrorStringW" int, intptr, int ; res = RasGetErrorStringW(ResourceId, varptr(lpszString), InBufSize) ; ResourceId : DWORD -> "int" ; lpszString : LPWSTR out -> "intptr" ; InBufSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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 版の利用を推奨。const std = @import("std");
extern "rasapi32" fn RasGetErrorStringW(
ResourceId: u32, // DWORD
lpszString: [*c]u16, // LPWSTR out
InBufSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RasGetErrorStringW(
ResourceId: uint32, # DWORD
lpszString: ptr uint16, # LPWSTR out
InBufSize: uint32 # DWORD
): uint32 {.importc: "RasGetErrorStringW", stdcall, dynlib: "RASAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rasapi32");
extern(Windows)
uint RasGetErrorStringW(
uint ResourceId, // DWORD
wchar* lpszString, // LPWSTR out
uint InBufSize // DWORD
);ccall((:RasGetErrorStringW, "RASAPI32.dll"), stdcall, UInt32,
(UInt32, Ptr{UInt16}, UInt32),
ResourceId, lpszString, InBufSize)
# ResourceId : DWORD -> UInt32
# lpszString : LPWSTR out -> Ptr{UInt16}
# InBufSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RasGetErrorStringW(
uint32_t ResourceId,
uint16_t* lpszString,
uint32_t InBufSize);
]]
local rasapi32 = ffi.load("rasapi32")
-- rasapi32.RasGetErrorStringW(ResourceId, lpszString, InBufSize)
-- ResourceId : DWORD
-- lpszString : LPWSTR out
-- InBufSize : DWORD
-- 構造体/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 RasGetErrorStringW = lib.func('__stdcall', 'RasGetErrorStringW', 'uint32_t', ['uint32_t', 'uint16_t *', 'uint32_t']);
// RasGetErrorStringW(ResourceId, lpszString, InBufSize)
// ResourceId : DWORD -> 'uint32_t'
// lpszString : LPWSTR out -> 'uint16_t *'
// InBufSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RASAPI32.dll", {
RasGetErrorStringW: { parameters: ["u32", "buffer", "u32"], result: "u32" },
});
// lib.symbols.RasGetErrorStringW(ResourceId, lpszString, InBufSize)
// ResourceId : DWORD -> "u32"
// lpszString : LPWSTR out -> "buffer"
// InBufSize : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RasGetErrorStringW(
uint32_t ResourceId,
uint16_t* lpszString,
uint32_t InBufSize);
C, "RASAPI32.dll");
// $ffi->RasGetErrorStringW(ResourceId, lpszString, InBufSize);
// ResourceId : DWORD
// lpszString : LPWSTR out
// InBufSize : DWORD
// 構造体/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 RasGetErrorStringW(
int ResourceId, // DWORD
char[] lpszString, // LPWSTR out
int InBufSize // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rasapi32")]
lib LibRASAPI32
fun RasGetErrorStringW = RasGetErrorStringW(
ResourceId : UInt32, # DWORD
lpszString : UInt16*, # LPWSTR out
InBufSize : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RasGetErrorStringWNative = Uint32 Function(Uint32, Pointer<Utf16>, Uint32);
typedef RasGetErrorStringWDart = int Function(int, Pointer<Utf16>, int);
final RasGetErrorStringW = DynamicLibrary.open('RASAPI32.dll')
.lookupFunction<RasGetErrorStringWNative, RasGetErrorStringWDart>('RasGetErrorStringW');
// ResourceId : DWORD -> Uint32
// lpszString : LPWSTR out -> Pointer<Utf16>
// InBufSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RasGetErrorStringW(
ResourceId: DWORD; // DWORD
lpszString: PWideChar; // LPWSTR out
InBufSize: DWORD // DWORD
): DWORD; stdcall;
external 'RASAPI32.dll' name 'RasGetErrorStringW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RasGetErrorStringW"
c_RasGetErrorStringW :: Word32 -> CWString -> Word32 -> IO Word32
-- ResourceId : DWORD -> Word32
-- lpszString : LPWSTR out -> CWString
-- InBufSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rasgeterrorstringw =
foreign "RasGetErrorStringW"
(uint32_t @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* ResourceId : DWORD -> uint32_t *)
(* lpszString : LPWSTR out -> (ptr uint16_t) *)
(* InBufSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rasapi32 (t "RASAPI32.dll"))
(cffi:use-foreign-library rasapi32)
(cffi:defcfun ("RasGetErrorStringW" ras-get-error-string-w :convention :stdcall) :uint32
(resource-id :uint32) ; DWORD
(lpsz-string :pointer) ; LPWSTR out
(in-buf-size :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RasGetErrorStringW = Win32::API::More->new('RASAPI32',
'DWORD RasGetErrorStringW(DWORD ResourceId, LPWSTR lpszString, DWORD InBufSize)');
# my $ret = $RasGetErrorStringW->Call($ResourceId, $lpszString, $InBufSize);
# ResourceId : DWORD -> DWORD
# lpszString : LPWSTR out -> LPWSTR
# InBufSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RasGetErrorStringA (ANSI版) — RASエラーコードに対応するエラーメッセージ文字列を取得する(ANSI版)。