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

NetDfsRemoveStdRoot

関数
スタンドアロンDFS名前空間のルートを削除する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD NetDfsRemoveStdRoot(
    LPWSTR ServerName,
    LPWSTR RootShare,
    DWORD Flags   // optional
);

パラメーター

名前方向説明
ServerNameLPWSTRin削除対象スタンドアロンDFSルートのサーバー名を示すワイド文字列。
RootShareLPWSTRin削除対象ルートの共有名を示すワイド文字列。
FlagsDWORDoptional予約パラメータ。通常0を指定する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetDfsRemoveStdRoot(
    LPWSTR ServerName,
    LPWSTR RootShare,
    DWORD Flags   // optional
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsRemoveStdRoot(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,   // LPWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string RootShare,   // LPWSTR
    uint Flags   // DWORD optional
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsRemoveStdRoot(
    <MarshalAs(UnmanagedType.LPWStr)> ServerName As String,   ' LPWSTR
    <MarshalAs(UnmanagedType.LPWStr)> RootShare As String,   ' LPWSTR
    Flags As UInteger   ' DWORD optional
) As UInteger
End Function
' ServerName : LPWSTR
' RootShare : LPWSTR
' Flags : DWORD optional
Declare PtrSafe Function NetDfsRemoveStdRoot Lib "netapi32" ( _
    ByVal ServerName As LongPtr, _
    ByVal RootShare 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

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

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

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetDfsRemoveStdRoot = netapi32.NewProc("NetDfsRemoveStdRoot")
)

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

extern "netapi32" fn NetDfsRemoveStdRoot(
    ServerName: [*c]const u16, // LPWSTR
    RootShare: [*c]const u16, // LPWSTR
    Flags: u32 // DWORD optional
) callconv(std.os.windows.WINAPI) u32;
proc NetDfsRemoveStdRoot(
    ServerName: WideCString,  # LPWSTR
    RootShare: WideCString,  # LPWSTR
    Flags: uint32  # DWORD optional
): uint32 {.importc: "NetDfsRemoveStdRoot", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetDfsRemoveStdRoot(
    const(wchar)* ServerName,   // LPWSTR
    const(wchar)* RootShare,   // LPWSTR
    uint Flags   // DWORD optional
);
ccall((:NetDfsRemoveStdRoot, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, UInt32),
      ServerName, RootShare, Flags)
# ServerName : LPWSTR -> Cwstring
# RootShare : LPWSTR -> Cwstring
# Flags : DWORD optional -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetDfsRemoveStdRoot(
    const uint16_t* ServerName,
    const uint16_t* RootShare,
    uint32_t Flags);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetDfsRemoveStdRoot(ServerName, RootShare, Flags)
-- ServerName : LPWSTR
-- RootShare : LPWSTR
-- Flags : DWORD optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetDfsRemoveStdRoot = lib.func('__stdcall', 'NetDfsRemoveStdRoot', 'uint32_t', ['str16', 'str16', 'uint32_t']);
// NetDfsRemoveStdRoot(ServerName, RootShare, Flags)
// ServerName : LPWSTR -> 'str16'
// RootShare : LPWSTR -> 'str16'
// Flags : DWORD optional -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetDfsRemoveStdRoot: { parameters: ["buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.NetDfsRemoveStdRoot(ServerName, RootShare, Flags)
// ServerName : LPWSTR -> "buffer"
// RootShare : LPWSTR -> "buffer"
// Flags : DWORD optional -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetDfsRemoveStdRoot(
    const uint16_t* ServerName,
    const uint16_t* RootShare,
    uint32_t Flags);
C, "NETAPI32.dll");
// $ffi->NetDfsRemoveStdRoot(ServerName, RootShare, Flags);
// ServerName : LPWSTR
// RootShare : LPWSTR
// Flags : DWORD optional
// 構造体/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 NetDfsRemoveStdRoot(
        WString ServerName,   // LPWSTR
        WString RootShare,   // LPWSTR
        int Flags   // DWORD optional
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetDfsRemoveStdRoot = NetDfsRemoveStdRoot(
    ServerName : UInt16*,   # LPWSTR
    RootShare : UInt16*,   # LPWSTR
    Flags : UInt32   # DWORD optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef NetDfsRemoveStdRootNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef NetDfsRemoveStdRootDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final NetDfsRemoveStdRoot = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetDfsRemoveStdRootNative, NetDfsRemoveStdRootDart>('NetDfsRemoveStdRoot');
// ServerName : LPWSTR -> Pointer<Utf16>
// RootShare : LPWSTR -> Pointer<Utf16>
// Flags : DWORD optional -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetDfsRemoveStdRoot(
  ServerName: PWideChar;   // LPWSTR
  RootShare: PWideChar;   // LPWSTR
  Flags: DWORD   // DWORD optional
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsRemoveStdRoot';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

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

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