ホーム › Storage.DistributedFileSystem › NetDfsGetClientInfo
NetDfsGetClientInfo
関数クライアント側のDFSエントリ情報を取得する。
シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD NetDfsGetClientInfo(
LPWSTR DfsEntryPath,
LPWSTR ServerName, // optional
LPWSTR ShareName, // optional
DWORD Level,
BYTE** Buffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DfsEntryPath | LPWSTR | in | クライアント側キャッシュ情報を取得するDFSリンクのUNCパスを示すワイド文字列。 |
| ServerName | LPWSTR | inoptional | 対象リンク先のサーバー名を示すワイド文字列。NULL可。 |
| ShareName | LPWSTR | inoptional | 対象リンク先の共有名を示すワイド文字列。NULL可。 |
| Level | DWORD | in | 取得する情報構造体のレベル。 |
| Buffer | BYTE** | out | 確保された情報を受け取るポインタへのポインタ。使用後NetApiBufferFreeで解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// NETAPI32.dll
#include <windows.h>
DWORD NetDfsGetClientInfo(
LPWSTR DfsEntryPath,
LPWSTR ServerName, // optional
LPWSTR ShareName, // optional
DWORD Level,
BYTE** Buffer
);[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsGetClientInfo(
[MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] string ServerName, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string ShareName, // LPWSTR optional
uint Level, // DWORD
IntPtr Buffer // BYTE** out
);<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsGetClientInfo(
<MarshalAs(UnmanagedType.LPWStr)> DfsEntryPath As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> ServerName As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> ShareName As String, ' LPWSTR optional
Level As UInteger, ' DWORD
Buffer As IntPtr ' BYTE** out
) As UInteger
End Function' DfsEntryPath : LPWSTR
' ServerName : LPWSTR optional
' ShareName : LPWSTR optional
' Level : DWORD
' Buffer : BYTE** out
Declare PtrSafe Function NetDfsGetClientInfo Lib "netapi32" ( _
ByVal DfsEntryPath As LongPtr, _
ByVal ServerName As LongPtr, _
ByVal ShareName As LongPtr, _
ByVal Level As Long, _
ByVal Buffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NetDfsGetClientInfo = ctypes.windll.netapi32.NetDfsGetClientInfo
NetDfsGetClientInfo.restype = wintypes.DWORD
NetDfsGetClientInfo.argtypes = [
wintypes.LPCWSTR, # DfsEntryPath : LPWSTR
wintypes.LPCWSTR, # ServerName : LPWSTR optional
wintypes.LPCWSTR, # ShareName : LPWSTR optional
wintypes.DWORD, # Level : DWORD
ctypes.c_void_p, # Buffer : BYTE** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NETAPI32.dll')
NetDfsGetClientInfo = Fiddle::Function.new(
lib['NetDfsGetClientInfo'],
[
Fiddle::TYPE_VOIDP, # DfsEntryPath : LPWSTR
Fiddle::TYPE_VOIDP, # ServerName : LPWSTR optional
Fiddle::TYPE_VOIDP, # ShareName : LPWSTR optional
-Fiddle::TYPE_INT, # Level : DWORD
Fiddle::TYPE_VOIDP, # Buffer : BYTE** out
],
-Fiddle::TYPE_INT)#[link(name = "netapi32")]
extern "system" {
fn NetDfsGetClientInfo(
DfsEntryPath: *mut u16, // LPWSTR
ServerName: *mut u16, // LPWSTR optional
ShareName: *mut u16, // LPWSTR optional
Level: u32, // DWORD
Buffer: *mut *mut u8 // BYTE** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetDfsGetClientInfo([MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, [MarshalAs(UnmanagedType.LPWStr)] string ServerName, [MarshalAs(UnmanagedType.LPWStr)] string ShareName, uint Level, IntPtr Buffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetDfsGetClientInfo' -Namespace Win32 -PassThru
# $api::NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer)#uselib "NETAPI32.dll"
#func global NetDfsGetClientInfo "NetDfsGetClientInfo" sptr, sptr, sptr, sptr, sptr
; NetDfsGetClientInfo DfsEntryPath, ServerName, ShareName, Level, varptr(Buffer) ; 戻り値は stat
; DfsEntryPath : LPWSTR -> "sptr"
; ServerName : LPWSTR optional -> "sptr"
; ShareName : LPWSTR optional -> "sptr"
; Level : DWORD -> "sptr"
; Buffer : BYTE** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NETAPI32.dll" #cfunc global NetDfsGetClientInfo "NetDfsGetClientInfo" wstr, wstr, wstr, int, var ; res = NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer) ; DfsEntryPath : LPWSTR -> "wstr" ; ServerName : LPWSTR optional -> "wstr" ; ShareName : LPWSTR optional -> "wstr" ; Level : DWORD -> "int" ; Buffer : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NETAPI32.dll" #cfunc global NetDfsGetClientInfo "NetDfsGetClientInfo" wstr, wstr, wstr, int, sptr ; res = NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, varptr(Buffer)) ; DfsEntryPath : LPWSTR -> "wstr" ; ServerName : LPWSTR optional -> "wstr" ; ShareName : LPWSTR optional -> "wstr" ; Level : DWORD -> "int" ; Buffer : BYTE** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD NetDfsGetClientInfo(LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName, DWORD Level, BYTE** Buffer) #uselib "NETAPI32.dll" #cfunc global NetDfsGetClientInfo "NetDfsGetClientInfo" wstr, wstr, wstr, int, var ; res = NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer) ; DfsEntryPath : LPWSTR -> "wstr" ; ServerName : LPWSTR optional -> "wstr" ; ShareName : LPWSTR optional -> "wstr" ; Level : DWORD -> "int" ; Buffer : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD NetDfsGetClientInfo(LPWSTR DfsEntryPath, LPWSTR ServerName, LPWSTR ShareName, DWORD Level, BYTE** Buffer) #uselib "NETAPI32.dll" #cfunc global NetDfsGetClientInfo "NetDfsGetClientInfo" wstr, wstr, wstr, int, intptr ; res = NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, varptr(Buffer)) ; DfsEntryPath : LPWSTR -> "wstr" ; ServerName : LPWSTR optional -> "wstr" ; ShareName : LPWSTR optional -> "wstr" ; Level : DWORD -> "int" ; Buffer : BYTE** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
procNetDfsGetClientInfo = netapi32.NewProc("NetDfsGetClientInfo")
)
// DfsEntryPath (LPWSTR), ServerName (LPWSTR optional), ShareName (LPWSTR optional), Level (DWORD), Buffer (BYTE** out)
r1, _, err := procNetDfsGetClientInfo.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DfsEntryPath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ShareName))),
uintptr(Level),
uintptr(Buffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction NetDfsGetClientInfo(
DfsEntryPath: PWideChar; // LPWSTR
ServerName: PWideChar; // LPWSTR optional
ShareName: PWideChar; // LPWSTR optional
Level: DWORD; // DWORD
Buffer: Pointer // BYTE** out
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetDfsGetClientInfo';result := DllCall("NETAPI32\NetDfsGetClientInfo"
, "WStr", DfsEntryPath ; LPWSTR
, "WStr", ServerName ; LPWSTR optional
, "WStr", ShareName ; LPWSTR optional
, "UInt", Level ; DWORD
, "Ptr", Buffer ; BYTE** out
, "UInt") ; return: DWORD●NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer) = DLL("NETAPI32.dll", "dword NetDfsGetClientInfo(char*, char*, char*, dword, void*)")
# 呼び出し: NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer)
# DfsEntryPath : LPWSTR -> "char*"
# ServerName : LPWSTR optional -> "char*"
# ShareName : LPWSTR optional -> "char*"
# Level : DWORD -> "dword"
# Buffer : BYTE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "netapi32" fn NetDfsGetClientInfo(
DfsEntryPath: [*c]const u16, // LPWSTR
ServerName: [*c]const u16, // LPWSTR optional
ShareName: [*c]const u16, // LPWSTR optional
Level: u32, // DWORD
Buffer: [*c][*c]u8 // BYTE** out
) callconv(std.os.windows.WINAPI) u32;proc NetDfsGetClientInfo(
DfsEntryPath: WideCString, # LPWSTR
ServerName: WideCString, # LPWSTR optional
ShareName: WideCString, # LPWSTR optional
Level: uint32, # DWORD
Buffer: ptr uint8 # BYTE** out
): uint32 {.importc: "NetDfsGetClientInfo", stdcall, dynlib: "NETAPI32.dll".}pragma(lib, "netapi32");
extern(Windows)
uint NetDfsGetClientInfo(
const(wchar)* DfsEntryPath, // LPWSTR
const(wchar)* ServerName, // LPWSTR optional
const(wchar)* ShareName, // LPWSTR optional
uint Level, // DWORD
ubyte** Buffer // BYTE** out
);ccall((:NetDfsGetClientInfo, "NETAPI32.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Cwstring, UInt32, Ptr{UInt8}),
DfsEntryPath, ServerName, ShareName, Level, Buffer)
# DfsEntryPath : LPWSTR -> Cwstring
# ServerName : LPWSTR optional -> Cwstring
# ShareName : LPWSTR optional -> Cwstring
# Level : DWORD -> UInt32
# Buffer : BYTE** out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NetDfsGetClientInfo(
const uint16_t* DfsEntryPath,
const uint16_t* ServerName,
const uint16_t* ShareName,
uint32_t Level,
uint8_t** Buffer);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer)
-- DfsEntryPath : LPWSTR
-- ServerName : LPWSTR optional
-- ShareName : LPWSTR optional
-- Level : DWORD
-- Buffer : BYTE** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetDfsGetClientInfo = lib.func('__stdcall', 'NetDfsGetClientInfo', 'uint32_t', ['str16', 'str16', 'str16', 'uint32_t', 'uint8_t *']);
// NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer)
// DfsEntryPath : LPWSTR -> 'str16'
// ServerName : LPWSTR optional -> 'str16'
// ShareName : LPWSTR optional -> 'str16'
// Level : DWORD -> 'uint32_t'
// Buffer : BYTE** out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NETAPI32.dll", {
NetDfsGetClientInfo: { parameters: ["buffer", "buffer", "buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer)
// DfsEntryPath : LPWSTR -> "buffer"
// ServerName : LPWSTR optional -> "buffer"
// ShareName : LPWSTR optional -> "buffer"
// Level : DWORD -> "u32"
// Buffer : BYTE** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NetDfsGetClientInfo(
const uint16_t* DfsEntryPath,
const uint16_t* ServerName,
const uint16_t* ShareName,
uint32_t Level,
uint8_t** Buffer);
C, "NETAPI32.dll");
// $ffi->NetDfsGetClientInfo(DfsEntryPath, ServerName, ShareName, Level, Buffer);
// DfsEntryPath : LPWSTR
// ServerName : LPWSTR optional
// ShareName : LPWSTR optional
// Level : DWORD
// Buffer : BYTE** out
// 構造体/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 NetDfsGetClientInfo(
WString DfsEntryPath, // LPWSTR
WString ServerName, // LPWSTR optional
WString ShareName, // LPWSTR optional
int Level, // DWORD
Pointer Buffer // BYTE** out
);
}@[Link("netapi32")]
lib LibNETAPI32
fun NetDfsGetClientInfo = NetDfsGetClientInfo(
DfsEntryPath : UInt16*, # LPWSTR
ServerName : UInt16*, # LPWSTR optional
ShareName : UInt16*, # LPWSTR optional
Level : UInt32, # DWORD
Buffer : UInt8** # BYTE** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NetDfsGetClientInfoNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Uint8>);
typedef NetDfsGetClientInfoDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Uint8>);
final NetDfsGetClientInfo = DynamicLibrary.open('NETAPI32.dll')
.lookupFunction<NetDfsGetClientInfoNative, NetDfsGetClientInfoDart>('NetDfsGetClientInfo');
// DfsEntryPath : LPWSTR -> Pointer<Utf16>
// ServerName : LPWSTR optional -> Pointer<Utf16>
// ShareName : LPWSTR optional -> Pointer<Utf16>
// Level : DWORD -> Uint32
// Buffer : BYTE** out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NetDfsGetClientInfo(
DfsEntryPath: PWideChar; // LPWSTR
ServerName: PWideChar; // LPWSTR optional
ShareName: PWideChar; // LPWSTR optional
Level: DWORD; // DWORD
Buffer: Pointer // BYTE** out
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetDfsGetClientInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NetDfsGetClientInfo"
c_NetDfsGetClientInfo :: CWString -> CWString -> CWString -> Word32 -> Ptr Word8 -> IO Word32
-- DfsEntryPath : LPWSTR -> CWString
-- ServerName : LPWSTR optional -> CWString
-- ShareName : LPWSTR optional -> CWString
-- Level : DWORD -> Word32
-- Buffer : BYTE** out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let netdfsgetclientinfo =
foreign "NetDfsGetClientInfo"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint8_t) @-> returning uint32_t)
(* DfsEntryPath : LPWSTR -> (ptr uint16_t) *)
(* ServerName : LPWSTR optional -> (ptr uint16_t) *)
(* ShareName : LPWSTR optional -> (ptr uint16_t) *)
(* Level : DWORD -> uint32_t *)
(* Buffer : BYTE** out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)
(cffi:defcfun ("NetDfsGetClientInfo" net-dfs-get-client-info :convention :stdcall) :uint32
(dfs-entry-path (:string :encoding :utf-16le)) ; LPWSTR
(server-name (:string :encoding :utf-16le)) ; LPWSTR optional
(share-name (:string :encoding :utf-16le)) ; LPWSTR optional
(level :uint32) ; DWORD
(buffer :pointer)) ; BYTE** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NetDfsGetClientInfo = Win32::API::More->new('NETAPI32',
'DWORD NetDfsGetClientInfo(LPCWSTR DfsEntryPath, LPCWSTR ServerName, LPCWSTR ShareName, DWORD Level, LPVOID Buffer)');
# my $ret = $NetDfsGetClientInfo->Call($DfsEntryPath, $ServerName, $ShareName, $Level, $Buffer);
# DfsEntryPath : LPWSTR -> LPCWSTR
# ServerName : LPWSTR optional -> LPCWSTR
# ShareName : LPWSTR optional -> LPCWSTR
# Level : DWORD -> DWORD
# Buffer : BYTE** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。