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

DavGetExtendedError

関数
WebDAV操作で発生した拡張エラー情報を取得する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DavGetExtendedError(
    HANDLE hFile,
    DWORD* ExtError,
    LPWSTR ExtErrorString,
    DWORD* cChSize
);

パラメーター

名前方向説明
hFileHANDLEin拡張エラー情報を取得する対象のファイルハンドル。
ExtErrorDWORD*out拡張エラーコードを受け取るDWORDポインタ。
ExtErrorStringLPWSTRout拡張エラー文字列を受け取る呼び出し側確保のバッファ。
cChSizeDWORD*inout入力でバッファ容量(文字数)、出力で必要サイズを受け渡すDWORDポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DavGetExtendedError(
    HANDLE hFile,
    DWORD* ExtError,
    LPWSTR ExtErrorString,
    DWORD* cChSize
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint DavGetExtendedError(
    IntPtr hFile,   // HANDLE
    out uint ExtError,   // DWORD* out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ExtErrorString,   // LPWSTR out
    ref uint cChSize   // DWORD* in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function DavGetExtendedError(
    hFile As IntPtr,   ' HANDLE
    <Out> ByRef ExtError As UInteger,   ' DWORD* out
    <MarshalAs(UnmanagedType.LPWStr)> ExtErrorString As System.Text.StringBuilder,   ' LPWSTR out
    ByRef cChSize As UInteger   ' DWORD* in/out
) As UInteger
End Function
' hFile : HANDLE
' ExtError : DWORD* out
' ExtErrorString : LPWSTR out
' cChSize : DWORD* in/out
Declare PtrSafe Function DavGetExtendedError Lib "netapi32" ( _
    ByVal hFile As LongPtr, _
    ByRef ExtError As Long, _
    ByVal ExtErrorString As LongPtr, _
    ByRef cChSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DavGetExtendedError = ctypes.windll.netapi32.DavGetExtendedError
DavGetExtendedError.restype = wintypes.DWORD
DavGetExtendedError.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
    ctypes.POINTER(wintypes.DWORD),  # ExtError : DWORD* out
    wintypes.LPWSTR,  # ExtErrorString : LPWSTR out
    ctypes.POINTER(wintypes.DWORD),  # cChSize : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
DavGetExtendedError = Fiddle::Function.new(
  lib['DavGetExtendedError'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
    Fiddle::TYPE_VOIDP,  # ExtError : DWORD* out
    Fiddle::TYPE_VOIDP,  # ExtErrorString : LPWSTR out
    Fiddle::TYPE_VOIDP,  # cChSize : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn DavGetExtendedError(
        hFile: *mut core::ffi::c_void,  // HANDLE
        ExtError: *mut u32,  // DWORD* out
        ExtErrorString: *mut u16,  // LPWSTR out
        cChSize: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint DavGetExtendedError(IntPtr hFile, out uint ExtError, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ExtErrorString, ref uint cChSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_DavGetExtendedError' -Namespace Win32 -PassThru
# $api::DavGetExtendedError(hFile, ExtError, ExtErrorString, cChSize)
#uselib "NETAPI32.dll"
#func global DavGetExtendedError "DavGetExtendedError" sptr, sptr, sptr, sptr
; DavGetExtendedError hFile, varptr(ExtError), varptr(ExtErrorString), varptr(cChSize)   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; ExtError : DWORD* out -> "sptr"
; ExtErrorString : LPWSTR out -> "sptr"
; cChSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global DavGetExtendedError "DavGetExtendedError" sptr, var, var, var
; res = DavGetExtendedError(hFile, ExtError, ExtErrorString, cChSize)
; hFile : HANDLE -> "sptr"
; ExtError : DWORD* out -> "var"
; ExtErrorString : LPWSTR out -> "var"
; cChSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DavGetExtendedError(HANDLE hFile, DWORD* ExtError, LPWSTR ExtErrorString, DWORD* cChSize)
#uselib "NETAPI32.dll"
#cfunc global DavGetExtendedError "DavGetExtendedError" intptr, var, var, var
; res = DavGetExtendedError(hFile, ExtError, ExtErrorString, cChSize)
; hFile : HANDLE -> "intptr"
; ExtError : DWORD* out -> "var"
; ExtErrorString : LPWSTR out -> "var"
; cChSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procDavGetExtendedError = netapi32.NewProc("DavGetExtendedError")
)

// hFile (HANDLE), ExtError (DWORD* out), ExtErrorString (LPWSTR out), cChSize (DWORD* in/out)
r1, _, err := procDavGetExtendedError.Call(
	uintptr(hFile),
	uintptr(ExtError),
	uintptr(ExtErrorString),
	uintptr(cChSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DavGetExtendedError(
  hFile: THandle;   // HANDLE
  ExtError: Pointer;   // DWORD* out
  ExtErrorString: PWideChar;   // LPWSTR out
  cChSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DavGetExtendedError';
result := DllCall("NETAPI32\DavGetExtendedError"
    , "Ptr", hFile   ; HANDLE
    , "Ptr", ExtError   ; DWORD* out
    , "Ptr", ExtErrorString   ; LPWSTR out
    , "Ptr", cChSize   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●DavGetExtendedError(hFile, ExtError, ExtErrorString, cChSize) = DLL("NETAPI32.dll", "dword DavGetExtendedError(void*, void*, char*, void*)")
# 呼び出し: DavGetExtendedError(hFile, ExtError, ExtErrorString, cChSize)
# hFile : HANDLE -> "void*"
# ExtError : DWORD* out -> "void*"
# ExtErrorString : LPWSTR out -> "char*"
# cChSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DavGetExtendedErrorNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
typedef DavGetExtendedErrorDart = int Function(Pointer<Void>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>);
final DavGetExtendedError = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<DavGetExtendedErrorNative, DavGetExtendedErrorDart>('DavGetExtendedError');
// hFile : HANDLE -> Pointer<Void>
// ExtError : DWORD* out -> Pointer<Uint32>
// ExtErrorString : LPWSTR out -> Pointer<Utf16>
// cChSize : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DavGetExtendedError(
  hFile: THandle;   // HANDLE
  ExtError: Pointer;   // DWORD* out
  ExtErrorString: PWideChar;   // LPWSTR out
  cChSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DavGetExtendedError';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DavGetExtendedError"
  c_DavGetExtendedError :: Ptr () -> Ptr Word32 -> CWString -> Ptr Word32 -> IO Word32
-- hFile : HANDLE -> Ptr ()
-- ExtError : DWORD* out -> Ptr Word32
-- ExtErrorString : LPWSTR out -> CWString
-- cChSize : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let davgetextendederror =
  foreign "DavGetExtendedError"
    ((ptr void) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* hFile : HANDLE -> (ptr void) *)
(* ExtError : DWORD* out -> (ptr uint32_t) *)
(* ExtErrorString : LPWSTR out -> (ptr uint16_t) *)
(* cChSize : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("DavGetExtendedError" dav-get-extended-error :convention :stdcall) :uint32
  (h-file :pointer)   ; HANDLE
  (ext-error :pointer)   ; DWORD* out
  (ext-error-string :pointer)   ; LPWSTR out
  (c-ch-size :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DavGetExtendedError = Win32::API::More->new('NETAPI32',
    'DWORD DavGetExtendedError(HANDLE hFile, LPVOID ExtError, LPWSTR ExtErrorString, LPVOID cChSize)');
# my $ret = $DavGetExtendedError->Call($hFile, $ExtError, $ExtErrorString, $cChSize);
# hFile : HANDLE -> HANDLE
# ExtError : DWORD* out -> LPVOID
# ExtErrorString : LPWSTR out -> LPWSTR
# cChSize : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。