Win32 API 日本語リファレンス
ホームMedia.DirectShow › AMGetErrorTextA

AMGetErrorTextA

関数
DirectShowのHRESULTに対応するエラーメッセージをANSIで取得する。
DLLQUARTZ.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

DWORD AMGetErrorTextA(
    HRESULT hr,
    LPSTR pbuffer,
    DWORD MaxLen
);

パラメーター

名前方向説明
hrHRESULTinエラーテキストを取得する対象のHRESULTエラーコード。
pbufferLPSTRoutエラー説明文字列を受け取るANSIバッファへのポインター。
MaxLenDWORDinpbufferバッファに格納可能な最大文字数。終端も考慮する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD AMGetErrorTextA(
    HRESULT hr,
    LPSTR pbuffer,
    DWORD MaxLen
);
[DllImport("QUARTZ.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint AMGetErrorTextA(
    int hr,   // HRESULT
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pbuffer,   // LPSTR out
    uint MaxLen   // DWORD
);
<DllImport("QUARTZ.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function AMGetErrorTextA(
    hr As Integer,   ' HRESULT
    <MarshalAs(UnmanagedType.LPStr)> pbuffer As System.Text.StringBuilder,   ' LPSTR out
    MaxLen As UInteger   ' DWORD
) As UInteger
End Function
' hr : HRESULT
' pbuffer : LPSTR out
' MaxLen : DWORD
Declare PtrSafe Function AMGetErrorTextA Lib "quartz" ( _
    ByVal hr As Long, _
    ByVal pbuffer As String, _
    ByVal MaxLen As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AMGetErrorTextA = ctypes.windll.quartz.AMGetErrorTextA
AMGetErrorTextA.restype = wintypes.DWORD
AMGetErrorTextA.argtypes = [
    ctypes.c_int,  # hr : HRESULT
    wintypes.LPSTR,  # pbuffer : LPSTR out
    wintypes.DWORD,  # MaxLen : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	quartz = windows.NewLazySystemDLL("QUARTZ.dll")
	procAMGetErrorTextA = quartz.NewProc("AMGetErrorTextA")
)

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

extern "quartz" fn AMGetErrorTextA(
    hr: i32, // HRESULT
    pbuffer: [*c]u8, // LPSTR out
    MaxLen: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc AMGetErrorTextA(
    hr: int32,  # HRESULT
    pbuffer: ptr char,  # LPSTR out
    MaxLen: uint32  # DWORD
): uint32 {.importc: "AMGetErrorTextA", stdcall, dynlib: "QUARTZ.dll".}
pragma(lib, "quartz");
extern(Windows)
uint AMGetErrorTextA(
    int hr,   // HRESULT
    char* pbuffer,   // LPSTR out
    uint MaxLen   // DWORD
);
ccall((:AMGetErrorTextA, "QUARTZ.dll"), stdcall, UInt32,
      (Int32, Ptr{UInt8}, UInt32),
      hr, pbuffer, MaxLen)
# hr : HRESULT -> Int32
# pbuffer : LPSTR out -> Ptr{UInt8}
# MaxLen : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t AMGetErrorTextA(
    int32_t hr,
    char* pbuffer,
    uint32_t MaxLen);
]]
local quartz = ffi.load("quartz")
-- quartz.AMGetErrorTextA(hr, pbuffer, MaxLen)
-- hr : HRESULT
-- pbuffer : LPSTR out
-- MaxLen : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('QUARTZ.dll');
const AMGetErrorTextA = lib.func('__stdcall', 'AMGetErrorTextA', 'uint32_t', ['int32_t', 'char *', 'uint32_t']);
// AMGetErrorTextA(hr, pbuffer, MaxLen)
// hr : HRESULT -> 'int32_t'
// pbuffer : LPSTR out -> 'char *'
// MaxLen : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("QUARTZ.dll", {
  AMGetErrorTextA: { parameters: ["i32", "buffer", "u32"], result: "u32" },
});
// lib.symbols.AMGetErrorTextA(hr, pbuffer, MaxLen)
// hr : HRESULT -> "i32"
// pbuffer : LPSTR out -> "buffer"
// MaxLen : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t AMGetErrorTextA(
    int32_t hr,
    char* pbuffer,
    uint32_t MaxLen);
C, "QUARTZ.dll");
// $ffi->AMGetErrorTextA(hr, pbuffer, MaxLen);
// hr : HRESULT
// pbuffer : LPSTR out
// MaxLen : 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 Quartz extends StdCallLibrary {
    Quartz INSTANCE = Native.load("quartz", Quartz.class, W32APIOptions.ASCII_OPTIONS);
    int AMGetErrorTextA(
        int hr,   // HRESULT
        byte[] pbuffer,   // LPSTR out
        int MaxLen   // DWORD
    );
}
@[Link("quartz")]
lib LibQUARTZ
  fun AMGetErrorTextA = AMGetErrorTextA(
    hr : Int32,   # HRESULT
    pbuffer : UInt8*,   # LPSTR out
    MaxLen : 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 AMGetErrorTextANative = Uint32 Function(Int32, Pointer<Utf8>, Uint32);
typedef AMGetErrorTextADart = int Function(int, Pointer<Utf8>, int);
final AMGetErrorTextA = DynamicLibrary.open('QUARTZ.dll')
    .lookupFunction<AMGetErrorTextANative, AMGetErrorTextADart>('AMGetErrorTextA');
// hr : HRESULT -> Int32
// pbuffer : LPSTR out -> Pointer<Utf8>
// MaxLen : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function AMGetErrorTextA(
  hr: Integer;   // HRESULT
  pbuffer: PAnsiChar;   // LPSTR out
  MaxLen: DWORD   // DWORD
): DWORD; stdcall;
  external 'QUARTZ.dll' name 'AMGetErrorTextA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "AMGetErrorTextA"
  c_AMGetErrorTextA :: Int32 -> CString -> Word32 -> IO Word32
-- hr : HRESULT -> Int32
-- pbuffer : LPSTR out -> CString
-- MaxLen : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let amgeterrortexta =
  foreign "AMGetErrorTextA"
    (int32_t @-> string @-> uint32_t @-> returning uint32_t)
(* hr : HRESULT -> int32_t *)
(* pbuffer : LPSTR out -> string *)
(* MaxLen : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library quartz (t "QUARTZ.dll"))
(cffi:use-foreign-library quartz)

(cffi:defcfun ("AMGetErrorTextA" amget-error-text-a :convention :stdcall) :uint32
  (hr :int32)   ; HRESULT
  (pbuffer :pointer)   ; LPSTR out
  (max-len :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $AMGetErrorTextA = Win32::API::More->new('QUARTZ',
    'DWORD AMGetErrorTextA(int hr, LPSTR pbuffer, DWORD MaxLen)');
# my $ret = $AMGetErrorTextA->Call($hr, $pbuffer, $MaxLen);
# hr : HRESULT -> int
# pbuffer : LPSTR out -> LPSTR
# MaxLen : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い