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