ホーム › NetworkManagement.WebDav › DavAddConnection
DavAddConnection
関数WebDAVサーバーへの接続を資格情報付きで確立する。
シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD DavAddConnection(
HANDLE* ConnectionHandle,
LPCWSTR RemoteName,
LPCWSTR UserName, // optional
LPCWSTR Password, // optional
BYTE* ClientCert,
DWORD CertSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ConnectionHandle | HANDLE* | inout |
| RemoteName | LPCWSTR | in |
| UserName | LPCWSTR | inoptional |
| Password | LPCWSTR | inoptional |
| ClientCert | BYTE* | in |
| CertSize | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// NETAPI32.dll
#include <windows.h>
DWORD DavAddConnection(
HANDLE* ConnectionHandle,
LPCWSTR RemoteName,
LPCWSTR UserName, // optional
LPCWSTR Password, // optional
BYTE* ClientCert,
DWORD CertSize
);[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint DavAddConnection(
IntPtr ConnectionHandle, // HANDLE* in/out
[MarshalAs(UnmanagedType.LPWStr)] string RemoteName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string UserName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string Password, // LPCWSTR optional
IntPtr ClientCert, // BYTE*
uint CertSize // DWORD
);<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function DavAddConnection(
ConnectionHandle As IntPtr, ' HANDLE* in/out
<MarshalAs(UnmanagedType.LPWStr)> RemoteName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> UserName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> Password As String, ' LPCWSTR optional
ClientCert As IntPtr, ' BYTE*
CertSize As UInteger ' DWORD
) As UInteger
End Function' ConnectionHandle : HANDLE* in/out
' RemoteName : LPCWSTR
' UserName : LPCWSTR optional
' Password : LPCWSTR optional
' ClientCert : BYTE*
' CertSize : DWORD
Declare PtrSafe Function DavAddConnection Lib "netapi32" ( _
ByVal ConnectionHandle As LongPtr, _
ByVal RemoteName As LongPtr, _
ByVal UserName As LongPtr, _
ByVal Password As LongPtr, _
ByVal ClientCert As LongPtr, _
ByVal CertSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DavAddConnection = ctypes.windll.netapi32.DavAddConnection
DavAddConnection.restype = wintypes.DWORD
DavAddConnection.argtypes = [
ctypes.c_void_p, # ConnectionHandle : HANDLE* in/out
wintypes.LPCWSTR, # RemoteName : LPCWSTR
wintypes.LPCWSTR, # UserName : LPCWSTR optional
wintypes.LPCWSTR, # Password : LPCWSTR optional
ctypes.POINTER(ctypes.c_ubyte), # ClientCert : BYTE*
wintypes.DWORD, # CertSize : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NETAPI32.dll')
DavAddConnection = Fiddle::Function.new(
lib['DavAddConnection'],
[
Fiddle::TYPE_VOIDP, # ConnectionHandle : HANDLE* in/out
Fiddle::TYPE_VOIDP, # RemoteName : LPCWSTR
Fiddle::TYPE_VOIDP, # UserName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # Password : LPCWSTR optional
Fiddle::TYPE_VOIDP, # ClientCert : BYTE*
-Fiddle::TYPE_INT, # CertSize : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "netapi32")]
extern "system" {
fn DavAddConnection(
ConnectionHandle: *mut *mut core::ffi::c_void, // HANDLE* in/out
RemoteName: *const u16, // LPCWSTR
UserName: *const u16, // LPCWSTR optional
Password: *const u16, // LPCWSTR optional
ClientCert: *mut u8, // BYTE*
CertSize: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint DavAddConnection(IntPtr ConnectionHandle, [MarshalAs(UnmanagedType.LPWStr)] string RemoteName, [MarshalAs(UnmanagedType.LPWStr)] string UserName, [MarshalAs(UnmanagedType.LPWStr)] string Password, IntPtr ClientCert, uint CertSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_DavAddConnection' -Namespace Win32 -PassThru
# $api::DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, ClientCert, CertSize)#uselib "NETAPI32.dll"
#func global DavAddConnection "DavAddConnection" sptr, sptr, sptr, sptr, sptr, sptr
; DavAddConnection ConnectionHandle, RemoteName, UserName, Password, varptr(ClientCert), CertSize ; 戻り値は stat
; ConnectionHandle : HANDLE* in/out -> "sptr"
; RemoteName : LPCWSTR -> "sptr"
; UserName : LPCWSTR optional -> "sptr"
; Password : LPCWSTR optional -> "sptr"
; ClientCert : BYTE* -> "sptr"
; CertSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NETAPI32.dll" #cfunc global DavAddConnection "DavAddConnection" sptr, wstr, wstr, wstr, var, int ; res = DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, ClientCert, CertSize) ; ConnectionHandle : HANDLE* in/out -> "sptr" ; RemoteName : LPCWSTR -> "wstr" ; UserName : LPCWSTR optional -> "wstr" ; Password : LPCWSTR optional -> "wstr" ; ClientCert : BYTE* -> "var" ; CertSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NETAPI32.dll" #cfunc global DavAddConnection "DavAddConnection" sptr, wstr, wstr, wstr, sptr, int ; res = DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, varptr(ClientCert), CertSize) ; ConnectionHandle : HANDLE* in/out -> "sptr" ; RemoteName : LPCWSTR -> "wstr" ; UserName : LPCWSTR optional -> "wstr" ; Password : LPCWSTR optional -> "wstr" ; ClientCert : BYTE* -> "sptr" ; CertSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DavAddConnection(HANDLE* ConnectionHandle, LPCWSTR RemoteName, LPCWSTR UserName, LPCWSTR Password, BYTE* ClientCert, DWORD CertSize) #uselib "NETAPI32.dll" #cfunc global DavAddConnection "DavAddConnection" intptr, wstr, wstr, wstr, var, int ; res = DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, ClientCert, CertSize) ; ConnectionHandle : HANDLE* in/out -> "intptr" ; RemoteName : LPCWSTR -> "wstr" ; UserName : LPCWSTR optional -> "wstr" ; Password : LPCWSTR optional -> "wstr" ; ClientCert : BYTE* -> "var" ; CertSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DavAddConnection(HANDLE* ConnectionHandle, LPCWSTR RemoteName, LPCWSTR UserName, LPCWSTR Password, BYTE* ClientCert, DWORD CertSize) #uselib "NETAPI32.dll" #cfunc global DavAddConnection "DavAddConnection" intptr, wstr, wstr, wstr, intptr, int ; res = DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, varptr(ClientCert), CertSize) ; ConnectionHandle : HANDLE* in/out -> "intptr" ; RemoteName : LPCWSTR -> "wstr" ; UserName : LPCWSTR optional -> "wstr" ; Password : LPCWSTR optional -> "wstr" ; ClientCert : BYTE* -> "intptr" ; CertSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
procDavAddConnection = netapi32.NewProc("DavAddConnection")
)
// ConnectionHandle (HANDLE* in/out), RemoteName (LPCWSTR), UserName (LPCWSTR optional), Password (LPCWSTR optional), ClientCert (BYTE*), CertSize (DWORD)
r1, _, err := procDavAddConnection.Call(
uintptr(ConnectionHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(RemoteName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(UserName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Password))),
uintptr(ClientCert),
uintptr(CertSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DavAddConnection(
ConnectionHandle: Pointer; // HANDLE* in/out
RemoteName: PWideChar; // LPCWSTR
UserName: PWideChar; // LPCWSTR optional
Password: PWideChar; // LPCWSTR optional
ClientCert: Pointer; // BYTE*
CertSize: DWORD // DWORD
): DWORD; stdcall;
external 'NETAPI32.dll' name 'DavAddConnection';result := DllCall("NETAPI32\DavAddConnection"
, "Ptr", ConnectionHandle ; HANDLE* in/out
, "WStr", RemoteName ; LPCWSTR
, "WStr", UserName ; LPCWSTR optional
, "WStr", Password ; LPCWSTR optional
, "Ptr", ClientCert ; BYTE*
, "UInt", CertSize ; DWORD
, "UInt") ; return: DWORD●DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, ClientCert, CertSize) = DLL("NETAPI32.dll", "dword DavAddConnection(void*, char*, char*, char*, void*, dword)")
# 呼び出し: DavAddConnection(ConnectionHandle, RemoteName, UserName, Password, ClientCert, CertSize)
# ConnectionHandle : HANDLE* in/out -> "void*"
# RemoteName : LPCWSTR -> "char*"
# UserName : LPCWSTR optional -> "char*"
# Password : LPCWSTR optional -> "char*"
# ClientCert : BYTE* -> "void*"
# CertSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。