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

DsBindWithCredA

関数
資格情報を指定してドメインコントローラへ接続する(ANSI版)。
DLLNTDSAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DsBindWithCredA(
    LPCSTR DomainControllerName,   // optional
    LPCSTR DnsDomainName,   // optional
    void* AuthIdentity,   // optional
    HANDLE* phDS
);

パラメーター

名前方向
DomainControllerNameLPCSTRinoptional
DnsDomainNameLPCSTRinoptional
AuthIdentityvoid*inoptional
phDSHANDLE*out

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DsBindWithCredA(
    LPCSTR DomainControllerName,   // optional
    LPCSTR DnsDomainName,   // optional
    void* AuthIdentity,   // optional
    HANDLE* phDS
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsBindWithCredA(
    [MarshalAs(UnmanagedType.LPStr)] string DomainControllerName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string DnsDomainName,   // LPCSTR optional
    IntPtr AuthIdentity,   // void* optional
    IntPtr phDS   // HANDLE* out
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsBindWithCredA(
    <MarshalAs(UnmanagedType.LPStr)> DomainControllerName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> DnsDomainName As String,   ' LPCSTR optional
    AuthIdentity As IntPtr,   ' void* optional
    phDS As IntPtr   ' HANDLE* out
) As UInteger
End Function
' DomainControllerName : LPCSTR optional
' DnsDomainName : LPCSTR optional
' AuthIdentity : void* optional
' phDS : HANDLE* out
Declare PtrSafe Function DsBindWithCredA Lib "ntdsapi" ( _
    ByVal DomainControllerName As String, _
    ByVal DnsDomainName As String, _
    ByVal AuthIdentity As LongPtr, _
    ByVal phDS As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DsBindWithCredA = ctypes.windll.ntdsapi.DsBindWithCredA
DsBindWithCredA.restype = wintypes.DWORD
DsBindWithCredA.argtypes = [
    wintypes.LPCSTR,  # DomainControllerName : LPCSTR optional
    wintypes.LPCSTR,  # DnsDomainName : LPCSTR optional
    ctypes.POINTER(None),  # AuthIdentity : void* optional
    ctypes.c_void_p,  # phDS : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NTDSAPI.dll')
DsBindWithCredA = Fiddle::Function.new(
  lib['DsBindWithCredA'],
  [
    Fiddle::TYPE_VOIDP,  # DomainControllerName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # DnsDomainName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # AuthIdentity : void* optional
    Fiddle::TYPE_VOIDP,  # phDS : HANDLE* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "ntdsapi")]
extern "system" {
    fn DsBindWithCredA(
        DomainControllerName: *const u8,  // LPCSTR optional
        DnsDomainName: *const u8,  // LPCSTR optional
        AuthIdentity: *mut (),  // void* optional
        phDS: *mut *mut core::ffi::c_void  // HANDLE* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint DsBindWithCredA([MarshalAs(UnmanagedType.LPStr)] string DomainControllerName, [MarshalAs(UnmanagedType.LPStr)] string DnsDomainName, IntPtr AuthIdentity, IntPtr phDS);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsBindWithCredA' -Namespace Win32 -PassThru
# $api::DsBindWithCredA(DomainControllerName, DnsDomainName, AuthIdentity, phDS)
#uselib "NTDSAPI.dll"
#func global DsBindWithCredA "DsBindWithCredA" sptr, sptr, sptr, sptr
; DsBindWithCredA DomainControllerName, DnsDomainName, AuthIdentity, phDS   ; 戻り値は stat
; DomainControllerName : LPCSTR optional -> "sptr"
; DnsDomainName : LPCSTR optional -> "sptr"
; AuthIdentity : void* optional -> "sptr"
; phDS : HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NTDSAPI.dll"
#cfunc global DsBindWithCredA "DsBindWithCredA" str, str, sptr, sptr
; res = DsBindWithCredA(DomainControllerName, DnsDomainName, AuthIdentity, phDS)
; DomainControllerName : LPCSTR optional -> "str"
; DnsDomainName : LPCSTR optional -> "str"
; AuthIdentity : void* optional -> "sptr"
; phDS : HANDLE* out -> "sptr"
; DWORD DsBindWithCredA(LPCSTR DomainControllerName, LPCSTR DnsDomainName, void* AuthIdentity, HANDLE* phDS)
#uselib "NTDSAPI.dll"
#cfunc global DsBindWithCredA "DsBindWithCredA" str, str, intptr, intptr
; res = DsBindWithCredA(DomainControllerName, DnsDomainName, AuthIdentity, phDS)
; DomainControllerName : LPCSTR optional -> "str"
; DnsDomainName : LPCSTR optional -> "str"
; AuthIdentity : void* optional -> "intptr"
; phDS : HANDLE* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsBindWithCredA = ntdsapi.NewProc("DsBindWithCredA")
)

// DomainControllerName (LPCSTR optional), DnsDomainName (LPCSTR optional), AuthIdentity (void* optional), phDS (HANDLE* out)
r1, _, err := procDsBindWithCredA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DomainControllerName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DnsDomainName))),
	uintptr(AuthIdentity),
	uintptr(phDS),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsBindWithCredA(
  DomainControllerName: PAnsiChar;   // LPCSTR optional
  DnsDomainName: PAnsiChar;   // LPCSTR optional
  AuthIdentity: Pointer;   // void* optional
  phDS: Pointer   // HANDLE* out
): DWORD; stdcall;
  external 'NTDSAPI.dll' name 'DsBindWithCredA';
result := DllCall("NTDSAPI\DsBindWithCredA"
    , "AStr", DomainControllerName   ; LPCSTR optional
    , "AStr", DnsDomainName   ; LPCSTR optional
    , "Ptr", AuthIdentity   ; void* optional
    , "Ptr", phDS   ; HANDLE* out
    , "UInt")   ; return: DWORD
●DsBindWithCredA(DomainControllerName, DnsDomainName, AuthIdentity, phDS) = DLL("NTDSAPI.dll", "dword DsBindWithCredA(char*, char*, void*, void*)")
# 呼び出し: DsBindWithCredA(DomainControllerName, DnsDomainName, AuthIdentity, phDS)
# DomainControllerName : LPCSTR optional -> "char*"
# DnsDomainName : LPCSTR optional -> "char*"
# AuthIdentity : void* optional -> "void*"
# phDS : HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。