Win32 API 日本語リファレンス
ホームNetworkManagement.WNet › WNetAddConnection4W

WNetAddConnection4W

関数
認証バッファを用いてネットワークリソースに接続する(Unicode版)。
DLLMPR.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetAddConnection4W(
    HWND hwndOwner,   // optional
    NETRESOURCEW* lpNetResource,
    void* pAuthBuffer,
    DWORD cbAuthBuffer,
    NET_CONNECT_FLAGS dwFlags,
    BYTE* lpUseOptions,
    DWORD cbUseOptions
);

パラメーター

名前方向
hwndOwnerHWNDinoptional
lpNetResourceNETRESOURCEW*in
pAuthBuffervoid*in
cbAuthBufferDWORDin
dwFlagsNET_CONNECT_FLAGSin
lpUseOptionsBYTE*in
cbUseOptionsDWORDin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetAddConnection4W(
    HWND hwndOwner,   // optional
    NETRESOURCEW* lpNetResource,
    void* pAuthBuffer,
    DWORD cbAuthBuffer,
    NET_CONNECT_FLAGS dwFlags,
    BYTE* lpUseOptions,
    DWORD cbUseOptions
);
[DllImport("MPR.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint WNetAddConnection4W(
    IntPtr hwndOwner,   // HWND optional
    IntPtr lpNetResource,   // NETRESOURCEW*
    IntPtr pAuthBuffer,   // void*
    uint cbAuthBuffer,   // DWORD
    uint dwFlags,   // NET_CONNECT_FLAGS
    IntPtr lpUseOptions,   // BYTE*
    uint cbUseOptions   // DWORD
);
<DllImport("MPR.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function WNetAddConnection4W(
    hwndOwner As IntPtr,   ' HWND optional
    lpNetResource As IntPtr,   ' NETRESOURCEW*
    pAuthBuffer As IntPtr,   ' void*
    cbAuthBuffer As UInteger,   ' DWORD
    dwFlags As UInteger,   ' NET_CONNECT_FLAGS
    lpUseOptions As IntPtr,   ' BYTE*
    cbUseOptions As UInteger   ' DWORD
) As UInteger
End Function
' hwndOwner : HWND optional
' lpNetResource : NETRESOURCEW*
' pAuthBuffer : void*
' cbAuthBuffer : DWORD
' dwFlags : NET_CONNECT_FLAGS
' lpUseOptions : BYTE*
' cbUseOptions : DWORD
Declare PtrSafe Function WNetAddConnection4W Lib "mpr" ( _
    ByVal hwndOwner As LongPtr, _
    ByVal lpNetResource As LongPtr, _
    ByVal pAuthBuffer As LongPtr, _
    ByVal cbAuthBuffer As Long, _
    ByVal dwFlags As Long, _
    ByVal lpUseOptions As LongPtr, _
    ByVal cbUseOptions As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WNetAddConnection4W = ctypes.windll.mpr.WNetAddConnection4W
WNetAddConnection4W.restype = wintypes.DWORD
WNetAddConnection4W.argtypes = [
    wintypes.HANDLE,  # hwndOwner : HWND optional
    ctypes.c_void_p,  # lpNetResource : NETRESOURCEW*
    ctypes.POINTER(None),  # pAuthBuffer : void*
    wintypes.DWORD,  # cbAuthBuffer : DWORD
    wintypes.DWORD,  # dwFlags : NET_CONNECT_FLAGS
    ctypes.POINTER(ctypes.c_ubyte),  # lpUseOptions : BYTE*
    wintypes.DWORD,  # cbUseOptions : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPR.dll')
WNetAddConnection4W = Fiddle::Function.new(
  lib['WNetAddConnection4W'],
  [
    Fiddle::TYPE_VOIDP,  # hwndOwner : HWND optional
    Fiddle::TYPE_VOIDP,  # lpNetResource : NETRESOURCEW*
    Fiddle::TYPE_VOIDP,  # pAuthBuffer : void*
    -Fiddle::TYPE_INT,  # cbAuthBuffer : DWORD
    -Fiddle::TYPE_INT,  # dwFlags : NET_CONNECT_FLAGS
    Fiddle::TYPE_VOIDP,  # lpUseOptions : BYTE*
    -Fiddle::TYPE_INT,  # cbUseOptions : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "mpr")]
extern "system" {
    fn WNetAddConnection4W(
        hwndOwner: *mut core::ffi::c_void,  // HWND optional
        lpNetResource: *mut NETRESOURCEW,  // NETRESOURCEW*
        pAuthBuffer: *mut (),  // void*
        cbAuthBuffer: u32,  // DWORD
        dwFlags: u32,  // NET_CONNECT_FLAGS
        lpUseOptions: *mut u8,  // BYTE*
        cbUseOptions: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MPR.dll", CharSet = CharSet.Unicode)]
public static extern uint WNetAddConnection4W(IntPtr hwndOwner, IntPtr lpNetResource, IntPtr pAuthBuffer, uint cbAuthBuffer, uint dwFlags, IntPtr lpUseOptions, uint cbUseOptions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetAddConnection4W' -Namespace Win32 -PassThru
# $api::WNetAddConnection4W(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
#uselib "MPR.dll"
#func global WNetAddConnection4W "WNetAddConnection4W" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; WNetAddConnection4W hwndOwner, varptr(lpNetResource), pAuthBuffer, cbAuthBuffer, dwFlags, varptr(lpUseOptions), cbUseOptions   ; 戻り値は stat
; hwndOwner : HWND optional -> "wptr"
; lpNetResource : NETRESOURCEW* -> "wptr"
; pAuthBuffer : void* -> "wptr"
; cbAuthBuffer : DWORD -> "wptr"
; dwFlags : NET_CONNECT_FLAGS -> "wptr"
; lpUseOptions : BYTE* -> "wptr"
; cbUseOptions : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MPR.dll"
#cfunc global WNetAddConnection4W "WNetAddConnection4W" sptr, var, sptr, int, int, var, int
; res = WNetAddConnection4W(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
; hwndOwner : HWND optional -> "sptr"
; lpNetResource : NETRESOURCEW* -> "var"
; pAuthBuffer : void* -> "sptr"
; cbAuthBuffer : DWORD -> "int"
; dwFlags : NET_CONNECT_FLAGS -> "int"
; lpUseOptions : BYTE* -> "var"
; cbUseOptions : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR WNetAddConnection4W(HWND hwndOwner, NETRESOURCEW* lpNetResource, void* pAuthBuffer, DWORD cbAuthBuffer, NET_CONNECT_FLAGS dwFlags, BYTE* lpUseOptions, DWORD cbUseOptions)
#uselib "MPR.dll"
#cfunc global WNetAddConnection4W "WNetAddConnection4W" intptr, var, intptr, int, int, var, int
; res = WNetAddConnection4W(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
; hwndOwner : HWND optional -> "intptr"
; lpNetResource : NETRESOURCEW* -> "var"
; pAuthBuffer : void* -> "intptr"
; cbAuthBuffer : DWORD -> "int"
; dwFlags : NET_CONNECT_FLAGS -> "int"
; lpUseOptions : BYTE* -> "var"
; cbUseOptions : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetAddConnection4W = mpr.NewProc("WNetAddConnection4W")
)

// hwndOwner (HWND optional), lpNetResource (NETRESOURCEW*), pAuthBuffer (void*), cbAuthBuffer (DWORD), dwFlags (NET_CONNECT_FLAGS), lpUseOptions (BYTE*), cbUseOptions (DWORD)
r1, _, err := procWNetAddConnection4W.Call(
	uintptr(hwndOwner),
	uintptr(lpNetResource),
	uintptr(pAuthBuffer),
	uintptr(cbAuthBuffer),
	uintptr(dwFlags),
	uintptr(lpUseOptions),
	uintptr(cbUseOptions),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetAddConnection4W(
  hwndOwner: THandle;   // HWND optional
  lpNetResource: Pointer;   // NETRESOURCEW*
  pAuthBuffer: Pointer;   // void*
  cbAuthBuffer: DWORD;   // DWORD
  dwFlags: DWORD;   // NET_CONNECT_FLAGS
  lpUseOptions: Pointer;   // BYTE*
  cbUseOptions: DWORD   // DWORD
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetAddConnection4W';
result := DllCall("MPR\WNetAddConnection4W"
    , "Ptr", hwndOwner   ; HWND optional
    , "Ptr", lpNetResource   ; NETRESOURCEW*
    , "Ptr", pAuthBuffer   ; void*
    , "UInt", cbAuthBuffer   ; DWORD
    , "UInt", dwFlags   ; NET_CONNECT_FLAGS
    , "Ptr", lpUseOptions   ; BYTE*
    , "UInt", cbUseOptions   ; DWORD
    , "UInt")   ; return: WIN32_ERROR
●WNetAddConnection4W(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions) = DLL("MPR.dll", "dword WNetAddConnection4W(void*, void*, void*, dword, dword, void*, dword)")
# 呼び出し: WNetAddConnection4W(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
# hwndOwner : HWND optional -> "void*"
# lpNetResource : NETRESOURCEW* -> "void*"
# pAuthBuffer : void* -> "void*"
# cbAuthBuffer : DWORD -> "dword"
# dwFlags : NET_CONNECT_FLAGS -> "dword"
# lpUseOptions : BYTE* -> "void*"
# cbUseOptions : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。