Win32 API 日本語リファレンス
ホームNetworking.WindowsWebServices › WsGetErrorString

WsGetErrorString

関数
エラーオブジェクトから文字列を取得する。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// webservices.dll
#include <windows.h>

HRESULT WsGetErrorString(
    WS_ERROR* error,
    DWORD index,
    WS_STRING* string
);

パラメーター

名前方向説明
errorWS_ERROR*in文字列を取得する対象のWS_ERRORオブジェクト。
indexDWORDin取得するエラー文字列の0始まりインデックス。
stringWS_STRING*out取得した文字列を受け取るWS_STRING出力ポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

// webservices.dll
#include <windows.h>

HRESULT WsGetErrorString(
    WS_ERROR* error,
    DWORD index,
    WS_STRING* string
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsGetErrorString(
    ref IntPtr error,   // WS_ERROR*
    uint index,   // DWORD
    IntPtr string   // WS_STRING* out
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsGetErrorString(
    ByRef [error] As IntPtr,   ' WS_ERROR*
    index As UInteger,   ' DWORD
    [string] As IntPtr   ' WS_STRING* out
) As Integer
End Function
' error : WS_ERROR*
' index : DWORD
' string : WS_STRING* out
Declare PtrSafe Function WsGetErrorString Lib "webservices" ( _
    ByRef error As LongPtr, _
    ByVal index As Long, _
    ByVal string As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WsGetErrorString = ctypes.windll.webservices.WsGetErrorString
WsGetErrorString.restype = ctypes.c_int
WsGetErrorString.argtypes = [
    ctypes.c_void_p,  # error : WS_ERROR*
    wintypes.DWORD,  # index : DWORD
    ctypes.c_void_p,  # string : WS_STRING* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsGetErrorString = webservices.NewProc("WsGetErrorString")
)

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

extern "webservices" fn WsGetErrorString(
    error: [*c]isize, // WS_ERROR*
    index: u32, // DWORD
    string: [*c]WS_STRING // WS_STRING* out
) callconv(std.os.windows.WINAPI) i32;
proc WsGetErrorString(
    error: ptr int,  # WS_ERROR*
    index: uint32,  # DWORD
    string: ptr WS_STRING  # WS_STRING* out
): int32 {.importc: "WsGetErrorString", stdcall, dynlib: "webservices.dll".}
pragma(lib, "webservices");
extern(Windows)
int WsGetErrorString(
    ptrdiff_t* error,   // WS_ERROR*
    uint index,   // DWORD
    WS_STRING* string   // WS_STRING* out
);
ccall((:WsGetErrorString, "webservices.dll"), stdcall, Int32,
      (Ptr{Int}, UInt32, Ptr{WS_STRING}),
      error, index, string)
# error : WS_ERROR* -> Ptr{Int}
# index : DWORD -> UInt32
# string : WS_STRING* out -> Ptr{WS_STRING}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WsGetErrorString(
    intptr_t* error,
    uint32_t index,
    void* string);
]]
local webservices = ffi.load("webservices")
-- webservices.WsGetErrorString(error, index, string)
-- error : WS_ERROR*
-- index : DWORD
-- string : WS_STRING* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('webservices.dll');
const WsGetErrorString = lib.func('__stdcall', 'WsGetErrorString', 'int32_t', ['intptr_t *', 'uint32_t', 'void *']);
// WsGetErrorString(error, index, string)
// error : WS_ERROR* -> 'intptr_t *'
// index : DWORD -> 'uint32_t'
// string : WS_STRING* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("webservices.dll", {
  WsGetErrorString: { parameters: ["pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.WsGetErrorString(error, index, string)
// error : WS_ERROR* -> "pointer"
// index : DWORD -> "u32"
// string : WS_STRING* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WsGetErrorString(
    intptr_t* error,
    uint32_t index,
    void* string);
C, "webservices.dll");
// $ffi->WsGetErrorString(error, index, string);
// error : WS_ERROR*
// index : DWORD
// string : WS_STRING* 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 Webservices extends StdCallLibrary {
    Webservices INSTANCE = Native.load("webservices", Webservices.class);
    int WsGetErrorString(
        LongByReference error,   // WS_ERROR*
        int index,   // DWORD
        Pointer string   // WS_STRING* out
    );
}
@[Link("webservices")]
lib Libwebservices
  fun WsGetErrorString = WsGetErrorString(
    error : LibC::SSizeT*,   # WS_ERROR*
    index : UInt32,   # DWORD
    string : WS_STRING*   # WS_STRING* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WsGetErrorStringNative = Int32 Function(Pointer<IntPtr>, Uint32, Pointer<Void>);
typedef WsGetErrorStringDart = int Function(Pointer<IntPtr>, int, Pointer<Void>);
final WsGetErrorString = DynamicLibrary.open('webservices.dll')
    .lookupFunction<WsGetErrorStringNative, WsGetErrorStringDart>('WsGetErrorString');
// error : WS_ERROR* -> Pointer<IntPtr>
// index : DWORD -> Uint32
// string : WS_STRING* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WsGetErrorString(
  error: Pointer;   // WS_ERROR*
  index: DWORD;   // DWORD
  string: Pointer   // WS_STRING* out
): Integer; stdcall;
  external 'webservices.dll' name 'WsGetErrorString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WsGetErrorString"
  c_WsGetErrorString :: Ptr CIntPtr -> Word32 -> Ptr () -> IO Int32
-- error : WS_ERROR* -> Ptr CIntPtr
-- index : DWORD -> Word32
-- string : WS_STRING* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsgeterrorstring =
  foreign "WsGetErrorString"
    ((ptr intptr_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* error : WS_ERROR* -> (ptr intptr_t) *)
(* index : DWORD -> uint32_t *)
(* string : WS_STRING* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library webservices (t "webservices.dll"))
(cffi:use-foreign-library webservices)

(cffi:defcfun ("WsGetErrorString" ws-get-error-string :convention :stdcall) :int32
  (error :pointer)   ; WS_ERROR*
  (index :uint32)   ; DWORD
  (string :pointer))   ; WS_STRING* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WsGetErrorString = Win32::API::More->new('webservices',
    'int WsGetErrorString(LPVOID error, DWORD index, LPVOID string)');
# my $ret = $WsGetErrorString->Call($error, $index, $string);
# error : WS_ERROR* -> LPVOID
# index : DWORD -> DWORD
# string : WS_STRING* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型