Win32 API 日本語リファレンス
ホームStorage.DistributedFileSystem › NetDfsAdd

NetDfsAdd

関数
DFS名前空間に新しいリンクまたはターゲットを追加する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD NetDfsAdd(
    LPWSTR DfsEntryPath,
    LPWSTR ServerName,
    LPWSTR ShareName,
    LPWSTR Comment,   // optional
    DWORD Flags
);

パラメーター

名前方向
DfsEntryPathLPWSTRin
ServerNameLPWSTRin
ShareNameLPWSTRin
CommentLPWSTRinoptional
FlagsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetDfsAdd(
    LPWSTR DfsEntryPath,
    LPWSTR ServerName,
    LPWSTR ShareName,
    LPWSTR Comment,   // optional
    DWORD Flags
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsAdd(
    [MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string ShareName,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string Comment,   // LPWSTR optional
    uint Flags   // DWORD
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsAdd(
    <MarshalAs(UnmanagedType.LPWStr)> DfsEntryPath As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> ServerName As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> ShareName As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> Comment As String,   ' LPWSTR optional
    Flags As UInteger   ' DWORD
) As UInteger
End Function
' DfsEntryPath : LPWSTR
' ServerName : LPWSTR
' ShareName : LPWSTR
' Comment : LPWSTR optional
' Flags : DWORD
Declare PtrSafe Function NetDfsAdd Lib "netapi32" ( _
    ByVal DfsEntryPath As LongPtr, _
    ByVal ServerName As LongPtr, _
    ByVal ShareName As LongPtr, _
    ByVal Comment As LongPtr, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetDfsAdd = ctypes.windll.netapi32.NetDfsAdd
NetDfsAdd.restype = wintypes.DWORD
NetDfsAdd.argtypes = [
    wintypes.LPCWSTR,  # DfsEntryPath : LPWSTR
    wintypes.LPCWSTR,  # ServerName : LPWSTR
    wintypes.LPCWSTR,  # ShareName : LPWSTR
    wintypes.LPCWSTR,  # Comment : LPWSTR optional
    wintypes.DWORD,  # Flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetDfsAdd = Fiddle::Function.new(
  lib['NetDfsAdd'],
  [
    Fiddle::TYPE_VOIDP,  # DfsEntryPath : LPWSTR
    Fiddle::TYPE_VOIDP,  # ServerName : LPWSTR
    Fiddle::TYPE_VOIDP,  # ShareName : LPWSTR
    Fiddle::TYPE_VOIDP,  # Comment : LPWSTR optional
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetDfsAdd(
        DfsEntryPath: *mut u16,  // LPWSTR
        ServerName: *mut u16,  // LPWSTR
        ShareName: *mut u16,  // LPWSTR
        Comment: *mut u16,  // LPWSTR optional
        Flags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetDfsAdd([MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, [MarshalAs(UnmanagedType.LPWStr)] string ServerName, [MarshalAs(UnmanagedType.LPWStr)] string ShareName, [MarshalAs(UnmanagedType.LPWStr)] string Comment, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetDfsAdd' -Namespace Win32 -PassThru
# $api::NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
#uselib "NETAPI32.dll"
#func global NetDfsAdd "NetDfsAdd" sptr, sptr, sptr, sptr, sptr
; NetDfsAdd DfsEntryPath, ServerName, ShareName, Comment, Flags   ; 戻り値は stat
; DfsEntryPath : LPWSTR -> "sptr"
; ServerName : LPWSTR -> "sptr"
; ShareName : LPWSTR -> "sptr"
; Comment : LPWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetDfsAdd "NetDfsAdd" wstr, wstr, wstr, wstr, int
; res = NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
; DfsEntryPath : LPWSTR -> "wstr"
; ServerName : LPWSTR -> "wstr"
; ShareName : LPWSTR -> "wstr"
; Comment : LPWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; DWORD NetDfsAdd(LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName, LPWSTR Comment, DWORD Flags)
#uselib "NETAPI32.dll"
#cfunc global NetDfsAdd "NetDfsAdd" wstr, wstr, wstr, wstr, int
; res = NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
; DfsEntryPath : LPWSTR -> "wstr"
; ServerName : LPWSTR -> "wstr"
; ShareName : LPWSTR -> "wstr"
; Comment : LPWSTR optional -> "wstr"
; Flags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetDfsAdd = netapi32.NewProc("NetDfsAdd")
)

// DfsEntryPath (LPWSTR), ServerName (LPWSTR), ShareName (LPWSTR), Comment (LPWSTR optional), Flags (DWORD)
r1, _, err := procNetDfsAdd.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DfsEntryPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ShareName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Comment))),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetDfsAdd(
  DfsEntryPath: PWideChar;   // LPWSTR
  ServerName: PWideChar;   // LPWSTR
  ShareName: PWideChar;   // LPWSTR
  Comment: PWideChar;   // LPWSTR optional
  Flags: DWORD   // DWORD
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsAdd';
result := DllCall("NETAPI32\NetDfsAdd"
    , "WStr", DfsEntryPath   ; LPWSTR
    , "WStr", ServerName   ; LPWSTR
    , "WStr", ShareName   ; LPWSTR
    , "WStr", Comment   ; LPWSTR optional
    , "UInt", Flags   ; DWORD
    , "UInt")   ; return: DWORD
●NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags) = DLL("NETAPI32.dll", "dword NetDfsAdd(char*, char*, char*, char*, dword)")
# 呼び出し: NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
# DfsEntryPath : LPWSTR -> "char*"
# ServerName : LPWSTR -> "char*"
# ShareName : LPWSTR -> "char*"
# Comment : LPWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。