ホーム › 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 | 資格情報入力ダイアログの親ウィンドウハンドル。不要ならNULL可。 |
| lpNetResource | NETRESOURCEW* | in | 接続先や種別を記述したNETRESOURCEW構造体へのポインタ。 |
| lpPassword | LPWSTR | inoptional | 接続に用いるパスワードのワイド文字列。既定資格情報ならNULL可。 |
| lpUserName | LPWSTR | inoptional | 接続に用いるユーザー名のワイド文字列。既定ユーザーならNULL可。 |
| dwFlags | NET_CONNECT_FLAGS | in | 接続動作を制御するNET_CONNECT_FLAGSフラグ。 |
戻り値の型: 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)。const std = @import("std");
extern "davclnt" fn NPAddConnection3(
hwndOwner: ?*anyopaque, // HWND optional
lpNetResource: [*c]NETRESOURCEW, // NETRESOURCEW*
lpPassword: [*c]const u16, // LPWSTR optional
lpUserName: [*c]const u16, // LPWSTR optional
dwFlags: u32 // NET_CONNECT_FLAGS
) callconv(std.os.windows.WINAPI) u32;proc NPAddConnection3(
hwndOwner: pointer, # HWND optional
lpNetResource: ptr NETRESOURCEW, # NETRESOURCEW*
lpPassword: WideCString, # LPWSTR optional
lpUserName: WideCString, # LPWSTR optional
dwFlags: uint32 # NET_CONNECT_FLAGS
): uint32 {.importc: "NPAddConnection3", stdcall, dynlib: "davclnt.dll".}pragma(lib, "davclnt");
extern(Windows)
uint NPAddConnection3(
void* hwndOwner, // HWND optional
NETRESOURCEW* lpNetResource, // NETRESOURCEW*
const(wchar)* lpPassword, // LPWSTR optional
const(wchar)* lpUserName, // LPWSTR optional
uint dwFlags // NET_CONNECT_FLAGS
);ccall((:NPAddConnection3, "davclnt.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{NETRESOURCEW}, Cwstring, Cwstring, UInt32),
hwndOwner, lpNetResource, lpPassword, lpUserName, dwFlags)
# hwndOwner : HWND optional -> Ptr{Cvoid}
# lpNetResource : NETRESOURCEW* -> Ptr{NETRESOURCEW}
# lpPassword : LPWSTR optional -> Cwstring
# lpUserName : LPWSTR optional -> Cwstring
# dwFlags : NET_CONNECT_FLAGS -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NPAddConnection3(
void* hwndOwner,
void* lpNetResource,
const uint16_t* lpPassword,
const uint16_t* lpUserName,
uint32_t dwFlags);
]]
local davclnt = ffi.load("davclnt")
-- davclnt.NPAddConnection3(hwndOwner, lpNetResource, lpPassword, lpUserName, dwFlags)
-- hwndOwner : HWND optional
-- lpNetResource : NETRESOURCEW*
-- lpPassword : LPWSTR optional
-- lpUserName : LPWSTR optional
-- dwFlags : NET_CONNECT_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('davclnt.dll');
const NPAddConnection3 = lib.func('__stdcall', 'NPAddConnection3', 'uint32_t', ['void *', 'void *', 'str16', 'str16', 'uint32_t']);
// NPAddConnection3(hwndOwner, lpNetResource, lpPassword, lpUserName, dwFlags)
// hwndOwner : HWND optional -> 'void *'
// lpNetResource : NETRESOURCEW* -> 'void *'
// lpPassword : LPWSTR optional -> 'str16'
// lpUserName : LPWSTR optional -> 'str16'
// dwFlags : NET_CONNECT_FLAGS -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("davclnt.dll", {
NPAddConnection3: { parameters: ["pointer", "pointer", "buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.NPAddConnection3(hwndOwner, lpNetResource, lpPassword, lpUserName, dwFlags)
// hwndOwner : HWND optional -> "pointer"
// lpNetResource : NETRESOURCEW* -> "pointer"
// lpPassword : LPWSTR optional -> "buffer"
// lpUserName : LPWSTR optional -> "buffer"
// dwFlags : NET_CONNECT_FLAGS -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NPAddConnection3(
void* hwndOwner,
void* lpNetResource,
const uint16_t* lpPassword,
const uint16_t* lpUserName,
uint32_t dwFlags);
C, "davclnt.dll");
// $ffi->NPAddConnection3(hwndOwner, lpNetResource, lpPassword, lpUserName, dwFlags);
// hwndOwner : HWND optional
// lpNetResource : NETRESOURCEW*
// lpPassword : LPWSTR optional
// lpUserName : LPWSTR optional
// dwFlags : NET_CONNECT_FLAGS
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Davclnt extends StdCallLibrary {
Davclnt INSTANCE = Native.load("davclnt", Davclnt.class);
int NPAddConnection3(
Pointer hwndOwner, // HWND optional
Pointer lpNetResource, // NETRESOURCEW*
WString lpPassword, // LPWSTR optional
WString lpUserName, // LPWSTR optional
int dwFlags // NET_CONNECT_FLAGS
);
}@[Link("davclnt")]
lib Libdavclnt
fun NPAddConnection3 = NPAddConnection3(
hwndOwner : Void*, # HWND optional
lpNetResource : NETRESOURCEW*, # NETRESOURCEW*
lpPassword : UInt16*, # LPWSTR optional
lpUserName : UInt16*, # LPWSTR optional
dwFlags : UInt32 # NET_CONNECT_FLAGS
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NPAddConnection3Native = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef NPAddConnection3Dart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final NPAddConnection3 = DynamicLibrary.open('davclnt.dll')
.lookupFunction<NPAddConnection3Native, NPAddConnection3Dart>('NPAddConnection3');
// hwndOwner : HWND optional -> Pointer<Void>
// lpNetResource : NETRESOURCEW* -> Pointer<Void>
// lpPassword : LPWSTR optional -> Pointer<Utf16>
// lpUserName : LPWSTR optional -> Pointer<Utf16>
// dwFlags : NET_CONNECT_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NPAddConnection3"
c_NPAddConnection3 :: Ptr () -> Ptr () -> CWString -> CWString -> Word32 -> IO Word32
-- hwndOwner : HWND optional -> Ptr ()
-- lpNetResource : NETRESOURCEW* -> Ptr ()
-- lpPassword : LPWSTR optional -> CWString
-- lpUserName : LPWSTR optional -> CWString
-- dwFlags : NET_CONNECT_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let npaddconnection3 =
foreign "NPAddConnection3"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* hwndOwner : HWND optional -> (ptr void) *)
(* lpNetResource : NETRESOURCEW* -> (ptr void) *)
(* lpPassword : LPWSTR optional -> (ptr uint16_t) *)
(* lpUserName : LPWSTR optional -> (ptr uint16_t) *)
(* dwFlags : NET_CONNECT_FLAGS -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library davclnt (t "davclnt.dll"))
(cffi:use-foreign-library davclnt)
(cffi:defcfun ("NPAddConnection3" npadd-connection3 :convention :stdcall) :uint32
(hwnd-owner :pointer) ; HWND optional
(lp-net-resource :pointer) ; NETRESOURCEW*
(lp-password (:string :encoding :utf-16le)) ; LPWSTR optional
(lp-user-name (:string :encoding :utf-16le)) ; LPWSTR optional
(dw-flags :uint32)) ; NET_CONNECT_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NPAddConnection3 = Win32::API::More->new('davclnt',
'DWORD NPAddConnection3(HANDLE hwndOwner, LPVOID lpNetResource, LPCWSTR lpPassword, LPCWSTR lpUserName, DWORD dwFlags)');
# my $ret = $NPAddConnection3->Call($hwndOwner, $lpNetResource, $lpPassword, $lpUserName, $dwFlags);
# hwndOwner : HWND optional -> HANDLE
# lpNetResource : NETRESOURCEW* -> LPVOID
# lpPassword : LPWSTR optional -> LPCWSTR
# lpUserName : LPWSTR optional -> LPCWSTR
# dwFlags : NET_CONNECT_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f NPAddConnection — ネットワークプロバイダー経由でリソースに接続する。
- f NPAddConnection4 — 認証バッファを用いてプロバイダー経由でリソースに接続する。