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

RouterGetErrorStringW

関数
ルーターのエラーコードに対応するエラー文字列を取得する(Unicode版)。
DLLrtutils.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

DWORD RouterGetErrorStringW(
    DWORD dwErrorCode,
    LPWSTR* lplpwszErrorString
);

パラメーター

名前方向説明
dwErrorCodeDWORDin対応するメッセージ文字列を取得するエラーコードを指定する。
lplpwszErrorStringLPWSTR*out取得したエラー文字列(Unicode)へのポインターを受け取る。使用後解放する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RouterGetErrorStringW(
    DWORD dwErrorCode,
    LPWSTR* lplpwszErrorString
);
[DllImport("rtutils.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RouterGetErrorStringW(
    uint dwErrorCode,   // DWORD
    IntPtr lplpwszErrorString   // LPWSTR* out
);
<DllImport("rtutils.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RouterGetErrorStringW(
    dwErrorCode As UInteger,   ' DWORD
    lplpwszErrorString As IntPtr   ' LPWSTR* out
) As UInteger
End Function
' dwErrorCode : DWORD
' lplpwszErrorString : LPWSTR* out
Declare PtrSafe Function RouterGetErrorStringW Lib "rtutils" ( _
    ByVal dwErrorCode As Long, _
    ByVal lplpwszErrorString 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

RouterGetErrorStringW = ctypes.windll.rtutils.RouterGetErrorStringW
RouterGetErrorStringW.restype = wintypes.DWORD
RouterGetErrorStringW.argtypes = [
    wintypes.DWORD,  # dwErrorCode : DWORD
    ctypes.c_void_p,  # lplpwszErrorString : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	rtutils = windows.NewLazySystemDLL("rtutils.dll")
	procRouterGetErrorStringW = rtutils.NewProc("RouterGetErrorStringW")
)

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

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

typedef RouterGetErrorStringWNative = Uint32 Function(Uint32, Pointer<Pointer<Utf16>>);
typedef RouterGetErrorStringWDart = int Function(int, Pointer<Pointer<Utf16>>);
final RouterGetErrorStringW = DynamicLibrary.open('rtutils.dll')
    .lookupFunction<RouterGetErrorStringWNative, RouterGetErrorStringWDart>('RouterGetErrorStringW');
// dwErrorCode : DWORD -> Uint32
// lplpwszErrorString : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RouterGetErrorStringW(
  dwErrorCode: DWORD;   // DWORD
  lplpwszErrorString: PPWideChar   // LPWSTR* out
): DWORD; stdcall;
  external 'rtutils.dll' name 'RouterGetErrorStringW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RouterGetErrorStringW"
  c_RouterGetErrorStringW :: Word32 -> Ptr CWString -> IO Word32
-- dwErrorCode : DWORD -> Word32
-- lplpwszErrorString : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let routergeterrorstringw =
  foreign "RouterGetErrorStringW"
    (uint32_t @-> (ptr (ptr uint16_t)) @-> returning uint32_t)
(* dwErrorCode : DWORD -> uint32_t *)
(* lplpwszErrorString : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rtutils (t "rtutils.dll"))
(cffi:use-foreign-library rtutils)

(cffi:defcfun ("RouterGetErrorStringW" router-get-error-string-w :convention :stdcall) :uint32
  (dw-error-code :uint32)   ; DWORD
  (lplpwsz-error-string :pointer))   ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RouterGetErrorStringW = Win32::API::More->new('rtutils',
    'DWORD RouterGetErrorStringW(DWORD dwErrorCode, LPVOID lplpwszErrorString)');
# my $ret = $RouterGetErrorStringW->Call($dwErrorCode, $lplpwszErrorString);
# dwErrorCode : DWORD -> DWORD
# lplpwszErrorString : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い