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