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

RouterGetErrorStringA

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

シグネチャ

// rtutils.dll  (ANSI / -A)
#include <windows.h>

DWORD RouterGetErrorStringA(
    DWORD dwErrorCode,
    LPSTR* lplpszErrorString
);

パラメーター

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

戻り値の型: DWORD

各言語での呼び出し定義

// rtutils.dll  (ANSI / -A)
#include <windows.h>

DWORD RouterGetErrorStringA(
    DWORD dwErrorCode,
    LPSTR* lplpszErrorString
);
[DllImport("rtutils.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RouterGetErrorStringA(
    uint dwErrorCode,   // DWORD
    IntPtr lplpszErrorString   // LPSTR* out
);
<DllImport("rtutils.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RouterGetErrorStringA(
    dwErrorCode As UInteger,   ' DWORD
    lplpszErrorString As IntPtr   ' LPSTR* out
) As UInteger
End Function
' dwErrorCode : DWORD
' lplpszErrorString : LPSTR* out
Declare PtrSafe Function RouterGetErrorStringA Lib "rtutils" ( _
    ByVal dwErrorCode As Long, _
    ByVal lplpszErrorString As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RouterGetErrorStringA = ctypes.windll.rtutils.RouterGetErrorStringA
RouterGetErrorStringA.restype = wintypes.DWORD
RouterGetErrorStringA.argtypes = [
    wintypes.DWORD,  # dwErrorCode : DWORD
    ctypes.c_void_p,  # lplpszErrorString : LPSTR* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	rtutils = windows.NewLazySystemDLL("rtutils.dll")
	procRouterGetErrorStringA = rtutils.NewProc("RouterGetErrorStringA")
)

// dwErrorCode (DWORD), lplpszErrorString (LPSTR* out)
r1, _, err := procRouterGetErrorStringA.Call(
	uintptr(dwErrorCode),
	uintptr(lplpszErrorString),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RouterGetErrorStringA(
  dwErrorCode: DWORD;   // DWORD
  lplpszErrorString: PPAnsiChar   // LPSTR* out
): DWORD; stdcall;
  external 'rtutils.dll' name 'RouterGetErrorStringA';
result := DllCall("rtutils\RouterGetErrorStringA"
    , "UInt", dwErrorCode   ; DWORD
    , "Ptr", lplpszErrorString   ; LPSTR* out
    , "UInt")   ; return: DWORD
●RouterGetErrorStringA(dwErrorCode, lplpszErrorString) = DLL("rtutils.dll", "dword RouterGetErrorStringA(dword, void*)")
# 呼び出し: RouterGetErrorStringA(dwErrorCode, lplpszErrorString)
# dwErrorCode : DWORD -> "dword"
# lplpszErrorString : LPSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "rtutils" fn RouterGetErrorStringA(
    dwErrorCode: u32, // DWORD
    lplpszErrorString: [*c][*c]u8 // LPSTR* out
) callconv(std.os.windows.WINAPI) u32;
proc RouterGetErrorStringA(
    dwErrorCode: uint32,  # DWORD
    lplpszErrorString: ptr cstring  # LPSTR* out
): uint32 {.importc: "RouterGetErrorStringA", stdcall, dynlib: "rtutils.dll".}
pragma(lib, "rtutils");
extern(Windows)
uint RouterGetErrorStringA(
    uint dwErrorCode,   // DWORD
    char** lplpszErrorString   // LPSTR* out
);
ccall((:RouterGetErrorStringA, "rtutils.dll"), stdcall, UInt32,
      (UInt32, Ptr{Ptr{UInt8}}),
      dwErrorCode, lplpszErrorString)
# dwErrorCode : DWORD -> UInt32
# lplpszErrorString : LPSTR* out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RouterGetErrorStringA(
    uint32_t dwErrorCode,
    char** lplpszErrorString);
]]
local rtutils = ffi.load("rtutils")
-- rtutils.RouterGetErrorStringA(dwErrorCode, lplpszErrorString)
-- dwErrorCode : DWORD
-- lplpszErrorString : LPSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('rtutils.dll');
const RouterGetErrorStringA = lib.func('__stdcall', 'RouterGetErrorStringA', 'uint32_t', ['uint32_t', 'void *']);
// RouterGetErrorStringA(dwErrorCode, lplpszErrorString)
// dwErrorCode : DWORD -> 'uint32_t'
// lplpszErrorString : LPSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("rtutils.dll", {
  RouterGetErrorStringA: { parameters: ["u32", "pointer"], result: "u32" },
});
// lib.symbols.RouterGetErrorStringA(dwErrorCode, lplpszErrorString)
// dwErrorCode : DWORD -> "u32"
// lplpszErrorString : LPSTR* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RouterGetErrorStringA(
    uint32_t dwErrorCode,
    char** lplpszErrorString);
C, "rtutils.dll");
// $ffi->RouterGetErrorStringA(dwErrorCode, lplpszErrorString);
// dwErrorCode : DWORD
// lplpszErrorString : LPSTR* 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.ASCII_OPTIONS);
    int RouterGetErrorStringA(
        int dwErrorCode,   // DWORD
        PointerByReference lplpszErrorString   // LPSTR* out
    );
}
@[Link("rtutils")]
lib Librtutils
  fun RouterGetErrorStringA = RouterGetErrorStringA(
    dwErrorCode : UInt32,   # DWORD
    lplpszErrorString : UInt8**   # LPSTR* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

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

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

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

(cffi:defcfun ("RouterGetErrorStringA" router-get-error-string-a :convention :stdcall) :uint32
  (dw-error-code :uint32)   ; DWORD
  (lplpsz-error-string :pointer))   ; LPSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RouterGetErrorStringA = Win32::API::More->new('rtutils',
    'DWORD RouterGetErrorStringA(DWORD dwErrorCode, LPVOID lplpszErrorString)');
# my $ret = $RouterGetErrorStringA->Call($dwErrorCode, $lplpszErrorString);
# dwErrorCode : DWORD -> DWORD
# lplpszErrorString : LPSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い