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

NPAddConnection4

関数
認証バッファを用いてプロバイダー経由でリソースに接続する。
DLLNTLANMAN.dll呼出規約winapi

シグネチャ

// NTLANMAN.dll
#include <windows.h>

DWORD NPAddConnection4(
    HWND hwndOwner,   // optional
    NETRESOURCEW* lpNetResource,
    void* lpAuthBuffer,   // optional
    DWORD cbAuthBuffer,
    DWORD dwFlags,
    BYTE* lpUseOptions,   // optional
    DWORD cbUseOptions
);

パラメーター

名前方向説明
hwndOwnerHWNDinoptional資格情報入力ダイアログの親ウィンドウハンドル。不要ならNULL可。
lpNetResourceNETRESOURCEW*in接続先や種別を記述したNETRESOURCEW構造体へのポインタ。
lpAuthBuffervoid*inoptional認証情報を格納したバッファへのポインタ。NULL可。
cbAuthBufferDWORDinlpAuthBufferのバイト数。
dwFlagsDWORDin接続動作を制御するフラグ。
lpUseOptionsBYTE*inoptional拡張接続オプションを格納したバッファへのポインタ。
cbUseOptionsDWORDinlpUseOptionsのバイト数。

戻り値の型: DWORD

各言語での呼び出し定義

// NTLANMAN.dll
#include <windows.h>

DWORD NPAddConnection4(
    HWND hwndOwner,   // optional
    NETRESOURCEW* lpNetResource,
    void* lpAuthBuffer,   // optional
    DWORD cbAuthBuffer,
    DWORD dwFlags,
    BYTE* lpUseOptions,   // optional
    DWORD cbUseOptions
);
[DllImport("NTLANMAN.dll", ExactSpelling = true)]
static extern uint NPAddConnection4(
    IntPtr hwndOwner,   // HWND optional
    IntPtr lpNetResource,   // NETRESOURCEW*
    IntPtr lpAuthBuffer,   // void* optional
    uint cbAuthBuffer,   // DWORD
    uint dwFlags,   // DWORD
    IntPtr lpUseOptions,   // BYTE* optional
    uint cbUseOptions   // DWORD
);
<DllImport("NTLANMAN.dll", ExactSpelling:=True)>
Public Shared Function NPAddConnection4(
    hwndOwner As IntPtr,   ' HWND optional
    lpNetResource As IntPtr,   ' NETRESOURCEW*
    lpAuthBuffer As IntPtr,   ' void* optional
    cbAuthBuffer As UInteger,   ' DWORD
    dwFlags As UInteger,   ' DWORD
    lpUseOptions As IntPtr,   ' BYTE* optional
    cbUseOptions As UInteger   ' DWORD
) As UInteger
End Function
' hwndOwner : HWND optional
' lpNetResource : NETRESOURCEW*
' lpAuthBuffer : void* optional
' cbAuthBuffer : DWORD
' dwFlags : DWORD
' lpUseOptions : BYTE* optional
' cbUseOptions : DWORD
Declare PtrSafe Function NPAddConnection4 Lib "ntlanman" ( _
    ByVal hwndOwner As LongPtr, _
    ByVal lpNetResource As LongPtr, _
    ByVal lpAuthBuffer 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

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

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

var (
	ntlanman = windows.NewLazySystemDLL("NTLANMAN.dll")
	procNPAddConnection4 = ntlanman.NewProc("NPAddConnection4")
)

// hwndOwner (HWND optional), lpNetResource (NETRESOURCEW*), lpAuthBuffer (void* optional), cbAuthBuffer (DWORD), dwFlags (DWORD), lpUseOptions (BYTE* optional), cbUseOptions (DWORD)
r1, _, err := procNPAddConnection4.Call(
	uintptr(hwndOwner),
	uintptr(lpNetResource),
	uintptr(lpAuthBuffer),
	uintptr(cbAuthBuffer),
	uintptr(dwFlags),
	uintptr(lpUseOptions),
	uintptr(cbUseOptions),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NPAddConnection4(
  hwndOwner: THandle;   // HWND optional
  lpNetResource: Pointer;   // NETRESOURCEW*
  lpAuthBuffer: Pointer;   // void* optional
  cbAuthBuffer: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  lpUseOptions: Pointer;   // BYTE* optional
  cbUseOptions: DWORD   // DWORD
): DWORD; stdcall;
  external 'NTLANMAN.dll' name 'NPAddConnection4';
result := DllCall("NTLANMAN\NPAddConnection4"
    , "Ptr", hwndOwner   ; HWND optional
    , "Ptr", lpNetResource   ; NETRESOURCEW*
    , "Ptr", lpAuthBuffer   ; void* optional
    , "UInt", cbAuthBuffer   ; DWORD
    , "UInt", dwFlags   ; DWORD
    , "Ptr", lpUseOptions   ; BYTE* optional
    , "UInt", cbUseOptions   ; DWORD
    , "UInt")   ; return: DWORD
●NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions) = DLL("NTLANMAN.dll", "dword NPAddConnection4(void*, void*, void*, dword, dword, void*, dword)")
# 呼び出し: NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
# hwndOwner : HWND optional -> "void*"
# lpNetResource : NETRESOURCEW* -> "void*"
# lpAuthBuffer : void* optional -> "void*"
# cbAuthBuffer : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# lpUseOptions : BYTE* optional -> "void*"
# cbUseOptions : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ntlanman" fn NPAddConnection4(
    hwndOwner: ?*anyopaque, // HWND optional
    lpNetResource: [*c]NETRESOURCEW, // NETRESOURCEW*
    lpAuthBuffer: ?*anyopaque, // void* optional
    cbAuthBuffer: u32, // DWORD
    dwFlags: u32, // DWORD
    lpUseOptions: [*c]u8, // BYTE* optional
    cbUseOptions: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc NPAddConnection4(
    hwndOwner: pointer,  # HWND optional
    lpNetResource: ptr NETRESOURCEW,  # NETRESOURCEW*
    lpAuthBuffer: pointer,  # void* optional
    cbAuthBuffer: uint32,  # DWORD
    dwFlags: uint32,  # DWORD
    lpUseOptions: ptr uint8,  # BYTE* optional
    cbUseOptions: uint32  # DWORD
): uint32 {.importc: "NPAddConnection4", stdcall, dynlib: "NTLANMAN.dll".}
pragma(lib, "ntlanman");
extern(Windows)
uint NPAddConnection4(
    void* hwndOwner,   // HWND optional
    NETRESOURCEW* lpNetResource,   // NETRESOURCEW*
    void* lpAuthBuffer,   // void* optional
    uint cbAuthBuffer,   // DWORD
    uint dwFlags,   // DWORD
    ubyte* lpUseOptions,   // BYTE* optional
    uint cbUseOptions   // DWORD
);
ccall((:NPAddConnection4, "NTLANMAN.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Ptr{NETRESOURCEW}, Ptr{Cvoid}, UInt32, UInt32, Ptr{UInt8}, UInt32),
      hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
# hwndOwner : HWND optional -> Ptr{Cvoid}
# lpNetResource : NETRESOURCEW* -> Ptr{NETRESOURCEW}
# lpAuthBuffer : void* optional -> Ptr{Cvoid}
# cbAuthBuffer : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# lpUseOptions : BYTE* optional -> Ptr{UInt8}
# cbUseOptions : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NPAddConnection4(
    void* hwndOwner,
    void* lpNetResource,
    void* lpAuthBuffer,
    uint32_t cbAuthBuffer,
    uint32_t dwFlags,
    uint8_t* lpUseOptions,
    uint32_t cbUseOptions);
]]
local ntlanman = ffi.load("ntlanman")
-- ntlanman.NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
-- hwndOwner : HWND optional
-- lpNetResource : NETRESOURCEW*
-- lpAuthBuffer : void* optional
-- cbAuthBuffer : DWORD
-- dwFlags : DWORD
-- lpUseOptions : BYTE* optional
-- cbUseOptions : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NTLANMAN.dll');
const NPAddConnection4 = lib.func('__stdcall', 'NPAddConnection4', 'uint32_t', ['void *', 'void *', 'void *', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t']);
// NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
// hwndOwner : HWND optional -> 'void *'
// lpNetResource : NETRESOURCEW* -> 'void *'
// lpAuthBuffer : void* optional -> 'void *'
// cbAuthBuffer : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// lpUseOptions : BYTE* optional -> 'uint8_t *'
// cbUseOptions : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NTLANMAN.dll", {
  NPAddConnection4: { parameters: ["pointer", "pointer", "pointer", "u32", "u32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions)
// hwndOwner : HWND optional -> "pointer"
// lpNetResource : NETRESOURCEW* -> "pointer"
// lpAuthBuffer : void* optional -> "pointer"
// cbAuthBuffer : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// lpUseOptions : BYTE* optional -> "pointer"
// cbUseOptions : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NPAddConnection4(
    void* hwndOwner,
    void* lpNetResource,
    void* lpAuthBuffer,
    uint32_t cbAuthBuffer,
    uint32_t dwFlags,
    uint8_t* lpUseOptions,
    uint32_t cbUseOptions);
C, "NTLANMAN.dll");
// $ffi->NPAddConnection4(hwndOwner, lpNetResource, lpAuthBuffer, cbAuthBuffer, dwFlags, lpUseOptions, cbUseOptions);
// hwndOwner : HWND optional
// lpNetResource : NETRESOURCEW*
// lpAuthBuffer : void* optional
// cbAuthBuffer : DWORD
// dwFlags : DWORD
// lpUseOptions : BYTE* optional
// cbUseOptions : DWORD
// 構造体/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 Ntlanman extends StdCallLibrary {
    Ntlanman INSTANCE = Native.load("ntlanman", Ntlanman.class);
    int NPAddConnection4(
        Pointer hwndOwner,   // HWND optional
        Pointer lpNetResource,   // NETRESOURCEW*
        Pointer lpAuthBuffer,   // void* optional
        int cbAuthBuffer,   // DWORD
        int dwFlags,   // DWORD
        byte[] lpUseOptions,   // BYTE* optional
        int cbUseOptions   // DWORD
    );
}
@[Link("ntlanman")]
lib LibNTLANMAN
  fun NPAddConnection4 = NPAddConnection4(
    hwndOwner : Void*,   # HWND optional
    lpNetResource : NETRESOURCEW*,   # NETRESOURCEW*
    lpAuthBuffer : Void*,   # void* optional
    cbAuthBuffer : UInt32,   # DWORD
    dwFlags : UInt32,   # DWORD
    lpUseOptions : UInt8*,   # BYTE* optional
    cbUseOptions : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NPAddConnection4Native = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Uint32, Pointer<Uint8>, Uint32);
typedef NPAddConnection4Dart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, Pointer<Uint8>, int);
final NPAddConnection4 = DynamicLibrary.open('NTLANMAN.dll')
    .lookupFunction<NPAddConnection4Native, NPAddConnection4Dart>('NPAddConnection4');
// hwndOwner : HWND optional -> Pointer<Void>
// lpNetResource : NETRESOURCEW* -> Pointer<Void>
// lpAuthBuffer : void* optional -> Pointer<Void>
// cbAuthBuffer : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// lpUseOptions : BYTE* optional -> Pointer<Uint8>
// cbUseOptions : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NPAddConnection4(
  hwndOwner: THandle;   // HWND optional
  lpNetResource: Pointer;   // NETRESOURCEW*
  lpAuthBuffer: Pointer;   // void* optional
  cbAuthBuffer: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  lpUseOptions: Pointer;   // BYTE* optional
  cbUseOptions: DWORD   // DWORD
): DWORD; stdcall;
  external 'NTLANMAN.dll' name 'NPAddConnection4';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NPAddConnection4"
  c_NPAddConnection4 :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> IO Word32
-- hwndOwner : HWND optional -> Ptr ()
-- lpNetResource : NETRESOURCEW* -> Ptr ()
-- lpAuthBuffer : void* optional -> Ptr ()
-- cbAuthBuffer : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- lpUseOptions : BYTE* optional -> Ptr Word8
-- cbUseOptions : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let npaddconnection4 =
  foreign "NPAddConnection4"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> returning uint32_t)
(* hwndOwner : HWND optional -> (ptr void) *)
(* lpNetResource : NETRESOURCEW* -> (ptr void) *)
(* lpAuthBuffer : void* optional -> (ptr void) *)
(* cbAuthBuffer : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* lpUseOptions : BYTE* optional -> (ptr uint8_t) *)
(* cbUseOptions : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ntlanman (t "NTLANMAN.dll"))
(cffi:use-foreign-library ntlanman)

(cffi:defcfun ("NPAddConnection4" npadd-connection4 :convention :stdcall) :uint32
  (hwnd-owner :pointer)   ; HWND optional
  (lp-net-resource :pointer)   ; NETRESOURCEW*
  (lp-auth-buffer :pointer)   ; void* optional
  (cb-auth-buffer :uint32)   ; DWORD
  (dw-flags :uint32)   ; DWORD
  (lp-use-options :pointer)   ; BYTE* optional
  (cb-use-options :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NPAddConnection4 = Win32::API::More->new('NTLANMAN',
    'DWORD NPAddConnection4(HANDLE hwndOwner, LPVOID lpNetResource, LPVOID lpAuthBuffer, DWORD cbAuthBuffer, DWORD dwFlags, LPVOID lpUseOptions, DWORD cbUseOptions)');
# my $ret = $NPAddConnection4->Call($hwndOwner, $lpNetResource, $lpAuthBuffer, $cbAuthBuffer, $dwFlags, $lpUseOptions, $cbUseOptions);
# hwndOwner : HWND optional -> HANDLE
# lpNetResource : NETRESOURCEW* -> LPVOID
# lpAuthBuffer : void* optional -> LPVOID
# cbAuthBuffer : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# lpUseOptions : BYTE* optional -> LPVOID
# cbUseOptions : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型