ホーム › Networking.ActiveDirectory › ADsSetLastError
ADsSetLastError
関数現在のスレッドのADSI拡張エラー情報を設定する。
シグネチャ
// ACTIVEDS.dll
#include <windows.h>
void ADsSetLastError(
DWORD dwErr,
LPCWSTR pszError,
LPCWSTR pszProvider
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dwErr | DWORD | in | スレッドの最終ADSIエラーとして設定するエラーコード。HRESULTやWin32コードを与える。 |
| pszError | LPCWSTR | in | エラーの説明文字列。NULL可。後でADsGetLastErrorで取得される。 |
| pszProvider | LPCWSTR | in | エラーを起こしたADSIプロバイダ名の文字列。NULL可。 |
戻り値の型: void
各言語での呼び出し定義
// ACTIVEDS.dll
#include <windows.h>
void ADsSetLastError(
DWORD dwErr,
LPCWSTR pszError,
LPCWSTR pszProvider
);[DllImport("ACTIVEDS.dll", ExactSpelling = true)]
static extern void ADsSetLastError(
uint dwErr, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pszError, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszProvider // LPCWSTR
);<DllImport("ACTIVEDS.dll", ExactSpelling:=True)>
Public Shared Sub ADsSetLastError(
dwErr As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszError As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszProvider As String ' LPCWSTR
)
End Sub' dwErr : DWORD
' pszError : LPCWSTR
' pszProvider : LPCWSTR
Declare PtrSafe Sub ADsSetLastError Lib "activeds" ( _
ByVal dwErr As Long, _
ByVal pszError As LongPtr, _
ByVal pszProvider As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ADsSetLastError = ctypes.windll.activeds.ADsSetLastError
ADsSetLastError.restype = None
ADsSetLastError.argtypes = [
wintypes.DWORD, # dwErr : DWORD
wintypes.LPCWSTR, # pszError : LPCWSTR
wintypes.LPCWSTR, # pszProvider : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ACTIVEDS.dll')
ADsSetLastError = Fiddle::Function.new(
lib['ADsSetLastError'],
[
-Fiddle::TYPE_INT, # dwErr : DWORD
Fiddle::TYPE_VOIDP, # pszError : LPCWSTR
Fiddle::TYPE_VOIDP, # pszProvider : LPCWSTR
],
Fiddle::TYPE_VOID)#[link(name = "activeds")]
extern "system" {
fn ADsSetLastError(
dwErr: u32, // DWORD
pszError: *const u16, // LPCWSTR
pszProvider: *const u16 // LPCWSTR
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ACTIVEDS.dll")]
public static extern void ADsSetLastError(uint dwErr, [MarshalAs(UnmanagedType.LPWStr)] string pszError, [MarshalAs(UnmanagedType.LPWStr)] string pszProvider);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ACTIVEDS_ADsSetLastError' -Namespace Win32 -PassThru
# $api::ADsSetLastError(dwErr, pszError, pszProvider)#uselib "ACTIVEDS.dll"
#func global ADsSetLastError "ADsSetLastError" sptr, sptr, sptr
; ADsSetLastError dwErr, pszError, pszProvider
; dwErr : DWORD -> "sptr"
; pszError : LPCWSTR -> "sptr"
; pszProvider : LPCWSTR -> "sptr"#uselib "ACTIVEDS.dll"
#func global ADsSetLastError "ADsSetLastError" int, wstr, wstr
; ADsSetLastError dwErr, pszError, pszProvider
; dwErr : DWORD -> "int"
; pszError : LPCWSTR -> "wstr"
; pszProvider : LPCWSTR -> "wstr"; void ADsSetLastError(DWORD dwErr, LPCWSTR pszError, LPCWSTR pszProvider)
#uselib "ACTIVEDS.dll"
#func global ADsSetLastError "ADsSetLastError" int, wstr, wstr
; ADsSetLastError dwErr, pszError, pszProvider
; dwErr : DWORD -> "int"
; pszError : LPCWSTR -> "wstr"
; pszProvider : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
activeds = windows.NewLazySystemDLL("ACTIVEDS.dll")
procADsSetLastError = activeds.NewProc("ADsSetLastError")
)
// dwErr (DWORD), pszError (LPCWSTR), pszProvider (LPCWSTR)
r1, _, err := procADsSetLastError.Call(
uintptr(dwErr),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszError))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszProvider))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure ADsSetLastError(
dwErr: DWORD; // DWORD
pszError: PWideChar; // LPCWSTR
pszProvider: PWideChar // LPCWSTR
); stdcall;
external 'ACTIVEDS.dll' name 'ADsSetLastError';result := DllCall("ACTIVEDS\ADsSetLastError"
, "UInt", dwErr ; DWORD
, "WStr", pszError ; LPCWSTR
, "WStr", pszProvider ; LPCWSTR
, "Int") ; return: void●ADsSetLastError(dwErr, pszError, pszProvider) = DLL("ACTIVEDS.dll", "int ADsSetLastError(dword, char*, char*)")
# 呼び出し: ADsSetLastError(dwErr, pszError, pszProvider)
# dwErr : DWORD -> "dword"
# pszError : LPCWSTR -> "char*"
# pszProvider : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "activeds" fn ADsSetLastError(
dwErr: u32, // DWORD
pszError: [*c]const u16, // LPCWSTR
pszProvider: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) void;proc ADsSetLastError(
dwErr: uint32, # DWORD
pszError: WideCString, # LPCWSTR
pszProvider: WideCString # LPCWSTR
) {.importc: "ADsSetLastError", stdcall, dynlib: "ACTIVEDS.dll".}pragma(lib, "activeds");
extern(Windows)
void ADsSetLastError(
uint dwErr, // DWORD
const(wchar)* pszError, // LPCWSTR
const(wchar)* pszProvider // LPCWSTR
);ccall((:ADsSetLastError, "ACTIVEDS.dll"), stdcall, Cvoid,
(UInt32, Cwstring, Cwstring),
dwErr, pszError, pszProvider)
# dwErr : DWORD -> UInt32
# pszError : LPCWSTR -> Cwstring
# pszProvider : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void ADsSetLastError(
uint32_t dwErr,
const uint16_t* pszError,
const uint16_t* pszProvider);
]]
local activeds = ffi.load("activeds")
-- activeds.ADsSetLastError(dwErr, pszError, pszProvider)
-- dwErr : DWORD
-- pszError : LPCWSTR
-- pszProvider : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ACTIVEDS.dll');
const ADsSetLastError = lib.func('__stdcall', 'ADsSetLastError', 'void', ['uint32_t', 'str16', 'str16']);
// ADsSetLastError(dwErr, pszError, pszProvider)
// dwErr : DWORD -> 'uint32_t'
// pszError : LPCWSTR -> 'str16'
// pszProvider : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ACTIVEDS.dll", {
ADsSetLastError: { parameters: ["u32", "buffer", "buffer"], result: "void" },
});
// lib.symbols.ADsSetLastError(dwErr, pszError, pszProvider)
// dwErr : DWORD -> "u32"
// pszError : LPCWSTR -> "buffer"
// pszProvider : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void ADsSetLastError(
uint32_t dwErr,
const uint16_t* pszError,
const uint16_t* pszProvider);
C, "ACTIVEDS.dll");
// $ffi->ADsSetLastError(dwErr, pszError, pszProvider);
// dwErr : DWORD
// pszError : LPCWSTR
// pszProvider : LPCWSTR
// 構造体/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 Activeds extends StdCallLibrary {
Activeds INSTANCE = Native.load("activeds", Activeds.class);
void ADsSetLastError(
int dwErr, // DWORD
WString pszError, // LPCWSTR
WString pszProvider // LPCWSTR
);
}@[Link("activeds")]
lib LibACTIVEDS
fun ADsSetLastError = ADsSetLastError(
dwErr : UInt32, # DWORD
pszError : UInt16*, # LPCWSTR
pszProvider : UInt16* # LPCWSTR
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ADsSetLastErrorNative = Void Function(Uint32, Pointer<Utf16>, Pointer<Utf16>);
typedef ADsSetLastErrorDart = void Function(int, Pointer<Utf16>, Pointer<Utf16>);
final ADsSetLastError = DynamicLibrary.open('ACTIVEDS.dll')
.lookupFunction<ADsSetLastErrorNative, ADsSetLastErrorDart>('ADsSetLastError');
// dwErr : DWORD -> Uint32
// pszError : LPCWSTR -> Pointer<Utf16>
// pszProvider : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure ADsSetLastError(
dwErr: DWORD; // DWORD
pszError: PWideChar; // LPCWSTR
pszProvider: PWideChar // LPCWSTR
); stdcall;
external 'ACTIVEDS.dll' name 'ADsSetLastError';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ADsSetLastError"
c_ADsSetLastError :: Word32 -> CWString -> CWString -> IO ()
-- dwErr : DWORD -> Word32
-- pszError : LPCWSTR -> CWString
-- pszProvider : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let adssetlasterror =
foreign "ADsSetLastError"
(uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning void)
(* dwErr : DWORD -> uint32_t *)
(* pszError : LPCWSTR -> (ptr uint16_t) *)
(* pszProvider : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library activeds (t "ACTIVEDS.dll"))
(cffi:use-foreign-library activeds)
(cffi:defcfun ("ADsSetLastError" ads-set-last-error :convention :stdcall) :void
(dw-err :uint32) ; DWORD
(psz-error (:string :encoding :utf-16le)) ; LPCWSTR
(psz-provider (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ADsSetLastError = Win32::API::More->new('ACTIVEDS',
'void ADsSetLastError(DWORD dwErr, LPCWSTR pszError, LPCWSTR pszProvider)');
# my $ret = $ADsSetLastError->Call($dwErr, $pszError, $pszProvider);
# dwErr : DWORD -> DWORD
# pszError : LPCWSTR -> LPCWSTR
# pszProvider : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。