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追加するDFSリンクのUNCパスを示すワイド文字列。
ServerNameLPWSTRinリンク先となるサーバー名を示すワイド文字列。
ShareNameLPWSTRinリンク先となる共有名(またはパス)を示すワイド文字列。
CommentLPWSTRinoptionalリンクに付与するコメントを示すワイド文字列。NULL可。
FlagsDWORDin追加動作を制御するフラグ。DFS_ADD_VOLUME等を指定する。

戻り値の型: 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)。
const std = @import("std");

extern "netapi32" fn NetDfsAdd(
    DfsEntryPath: [*c]const u16, // LPWSTR
    ServerName: [*c]const u16, // LPWSTR
    ShareName: [*c]const u16, // LPWSTR
    Comment: [*c]const u16, // LPWSTR optional
    Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc NetDfsAdd(
    DfsEntryPath: WideCString,  # LPWSTR
    ServerName: WideCString,  # LPWSTR
    ShareName: WideCString,  # LPWSTR
    Comment: WideCString,  # LPWSTR optional
    Flags: uint32  # DWORD
): uint32 {.importc: "NetDfsAdd", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetDfsAdd(
    const(wchar)* DfsEntryPath,   // LPWSTR
    const(wchar)* ServerName,   // LPWSTR
    const(wchar)* ShareName,   // LPWSTR
    const(wchar)* Comment,   // LPWSTR optional
    uint Flags   // DWORD
);
ccall((:NetDfsAdd, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Cwstring, Cwstring, UInt32),
      DfsEntryPath, ServerName, ShareName, Comment, Flags)
# DfsEntryPath : LPWSTR -> Cwstring
# ServerName : LPWSTR -> Cwstring
# ShareName : LPWSTR -> Cwstring
# Comment : LPWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetDfsAdd(
    const uint16_t* DfsEntryPath,
    const uint16_t* ServerName,
    const uint16_t* ShareName,
    const uint16_t* Comment,
    uint32_t Flags);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
-- DfsEntryPath : LPWSTR
-- ServerName : LPWSTR
-- ShareName : LPWSTR
-- Comment : LPWSTR optional
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetDfsAdd = lib.func('__stdcall', 'NetDfsAdd', 'uint32_t', ['str16', 'str16', 'str16', 'str16', 'uint32_t']);
// NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
// DfsEntryPath : LPWSTR -> 'str16'
// ServerName : LPWSTR -> 'str16'
// ShareName : LPWSTR -> 'str16'
// Comment : LPWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetDfsAdd: { parameters: ["buffer", "buffer", "buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags)
// DfsEntryPath : LPWSTR -> "buffer"
// ServerName : LPWSTR -> "buffer"
// ShareName : LPWSTR -> "buffer"
// Comment : LPWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetDfsAdd(
    const uint16_t* DfsEntryPath,
    const uint16_t* ServerName,
    const uint16_t* ShareName,
    const uint16_t* Comment,
    uint32_t Flags);
C, "NETAPI32.dll");
// $ffi->NetDfsAdd(DfsEntryPath, ServerName, ShareName, Comment, Flags);
// DfsEntryPath : LPWSTR
// ServerName : LPWSTR
// ShareName : LPWSTR
// Comment : LPWSTR optional
// Flags : 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 Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int NetDfsAdd(
        WString DfsEntryPath,   // LPWSTR
        WString ServerName,   // LPWSTR
        WString ShareName,   // LPWSTR
        WString Comment,   // LPWSTR optional
        int Flags   // DWORD
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetDfsAdd = NetDfsAdd(
    DfsEntryPath : UInt16*,   # LPWSTR
    ServerName : UInt16*,   # LPWSTR
    ShareName : UInt16*,   # LPWSTR
    Comment : UInt16*,   # LPWSTR optional
    Flags : 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 NetDfsAddNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef NetDfsAddDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int);
final NetDfsAdd = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetDfsAddNative, NetDfsAddDart>('NetDfsAdd');
// DfsEntryPath : LPWSTR -> Pointer<Utf16>
// ServerName : LPWSTR -> Pointer<Utf16>
// ShareName : LPWSTR -> Pointer<Utf16>
// Comment : LPWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetDfsAdd"
  c_NetDfsAdd :: CWString -> CWString -> CWString -> CWString -> Word32 -> IO Word32
-- DfsEntryPath : LPWSTR -> CWString
-- ServerName : LPWSTR -> CWString
-- ShareName : LPWSTR -> CWString
-- Comment : LPWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netdfsadd =
  foreign "NetDfsAdd"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* DfsEntryPath : LPWSTR -> (ptr uint16_t) *)
(* ServerName : LPWSTR -> (ptr uint16_t) *)
(* ShareName : LPWSTR -> (ptr uint16_t) *)
(* Comment : LPWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetDfsAdd" net-dfs-add :convention :stdcall) :uint32
  (dfs-entry-path (:string :encoding :utf-16le))   ; LPWSTR
  (server-name (:string :encoding :utf-16le))   ; LPWSTR
  (share-name (:string :encoding :utf-16le))   ; LPWSTR
  (comment (:string :encoding :utf-16le))   ; LPWSTR optional
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetDfsAdd = Win32::API::More->new('NETAPI32',
    'DWORD NetDfsAdd(LPCWSTR DfsEntryPath, LPCWSTR ServerName, LPCWSTR ShareName, LPCWSTR Comment, DWORD Flags)');
# my $ret = $NetDfsAdd->Call($DfsEntryPath, $ServerName, $ShareName, $Comment, $Flags);
# DfsEntryPath : LPWSTR -> LPCWSTR
# ServerName : LPWSTR -> LPCWSTR
# ShareName : LPWSTR -> LPCWSTR
# Comment : LPWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。