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

WNetAddConnection4A

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

シグネチャ

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

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

パラメーター

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

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR WNetAddConnection4A(
    HWND hwndOwner,   // optional
    NETRESOURCEA* lpNetResource,
    void* pAuthBuffer,
    DWORD cbAuthBuffer,
    NET_CONNECT_FLAGS dwFlags,
    BYTE* lpUseOptions,
    DWORD cbUseOptions
);
[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetAddConnection4A(
    IntPtr hwndOwner,   // HWND optional
    IntPtr lpNetResource,   // NETRESOURCEA*
    IntPtr pAuthBuffer,   // void*
    uint cbAuthBuffer,   // DWORD
    uint dwFlags,   // NET_CONNECT_FLAGS
    IntPtr lpUseOptions,   // BYTE*
    uint cbUseOptions   // DWORD
);
<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetAddConnection4A(
    hwndOwner As IntPtr,   ' HWND optional
    lpNetResource As IntPtr,   ' NETRESOURCEA*
    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 : NETRESOURCEA*
' pAuthBuffer : void*
' cbAuthBuffer : DWORD
' dwFlags : NET_CONNECT_FLAGS
' lpUseOptions : BYTE*
' cbUseOptions : DWORD
Declare PtrSafe Function WNetAddConnection4A 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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WNetAddConnection4A = ctypes.windll.mpr.WNetAddConnection4A
WNetAddConnection4A.restype = wintypes.DWORD
WNetAddConnection4A.argtypes = [
    wintypes.HANDLE,  # hwndOwner : HWND optional
    ctypes.c_void_p,  # lpNetResource : NETRESOURCEA*
    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')
WNetAddConnection4A = Fiddle::Function.new(
  lib['WNetAddConnection4A'],
  [
    Fiddle::TYPE_VOIDP,  # hwndOwner : HWND optional
    Fiddle::TYPE_VOIDP,  # lpNetResource : NETRESOURCEA*
    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)
#[link(name = "mpr")]
extern "system" {
    fn WNetAddConnection4A(
        hwndOwner: *mut core::ffi::c_void,  // HWND optional
        lpNetResource: *mut NETRESOURCEA,  // NETRESOURCEA*
        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.Ansi)]
public static extern uint WNetAddConnection4A(IntPtr hwndOwner, IntPtr lpNetResource, IntPtr pAuthBuffer, uint cbAuthBuffer, uint dwFlags, IntPtr lpUseOptions, uint cbUseOptions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetAddConnection4A' -Namespace Win32 -PassThru
# $api::WNetAddConnection4A(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
#uselib "MPR.dll"
#func global WNetAddConnection4A "WNetAddConnection4A" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WNetAddConnection4A hwndOwner, varptr(lpNetResource), pAuthBuffer, cbAuthBuffer, dwFlags, varptr(lpUseOptions), cbUseOptions   ; 戻り値は stat
; hwndOwner : HWND optional -> "sptr"
; lpNetResource : NETRESOURCEA* -> "sptr"
; pAuthBuffer : void* -> "sptr"
; cbAuthBuffer : DWORD -> "sptr"
; dwFlags : NET_CONNECT_FLAGS -> "sptr"
; lpUseOptions : BYTE* -> "sptr"
; cbUseOptions : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MPR.dll"
#cfunc global WNetAddConnection4A "WNetAddConnection4A" sptr, var, sptr, int, int, var, int
; res = WNetAddConnection4A(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
; hwndOwner : HWND optional -> "sptr"
; lpNetResource : NETRESOURCEA* -> "var"
; pAuthBuffer : void* -> "sptr"
; cbAuthBuffer : DWORD -> "int"
; dwFlags : NET_CONNECT_FLAGS -> "int"
; lpUseOptions : BYTE* -> "var"
; cbUseOptions : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR WNetAddConnection4A(HWND hwndOwner, NETRESOURCEA* lpNetResource, void* pAuthBuffer, DWORD cbAuthBuffer, NET_CONNECT_FLAGS dwFlags, BYTE* lpUseOptions, DWORD cbUseOptions)
#uselib "MPR.dll"
#cfunc global WNetAddConnection4A "WNetAddConnection4A" intptr, var, intptr, int, int, var, int
; res = WNetAddConnection4A(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
; hwndOwner : HWND optional -> "intptr"
; lpNetResource : NETRESOURCEA* -> "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")
	procWNetAddConnection4A = mpr.NewProc("WNetAddConnection4A")
)

// hwndOwner (HWND optional), lpNetResource (NETRESOURCEA*), pAuthBuffer (void*), cbAuthBuffer (DWORD), dwFlags (NET_CONNECT_FLAGS), lpUseOptions (BYTE*), cbUseOptions (DWORD)
r1, _, err := procWNetAddConnection4A.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 WNetAddConnection4A(
  hwndOwner: THandle;   // HWND optional
  lpNetResource: Pointer;   // NETRESOURCEA*
  pAuthBuffer: Pointer;   // void*
  cbAuthBuffer: DWORD;   // DWORD
  dwFlags: DWORD;   // NET_CONNECT_FLAGS
  lpUseOptions: Pointer;   // BYTE*
  cbUseOptions: DWORD   // DWORD
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetAddConnection4A';
result := DllCall("MPR\WNetAddConnection4A"
    , "Ptr", hwndOwner   ; HWND optional
    , "Ptr", lpNetResource   ; NETRESOURCEA*
    , "Ptr", pAuthBuffer   ; void*
    , "UInt", cbAuthBuffer   ; DWORD
    , "UInt", dwFlags   ; NET_CONNECT_FLAGS
    , "Ptr", lpUseOptions   ; BYTE*
    , "UInt", cbUseOptions   ; DWORD
    , "UInt")   ; return: WIN32_ERROR
●WNetAddConnection4A(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions) = DLL("MPR.dll", "dword WNetAddConnection4A(void*, void*, void*, dword, dword, void*, dword)")
# 呼び出し: WNetAddConnection4A(hwndOwner, lpNetResource, pAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
# hwndOwner : HWND optional -> "void*"
# lpNetResource : NETRESOURCEA* -> "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)。