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

WNetGetResourceInformationW

関数
指定したネットワークリソースの詳細情報を取得する(Unicode版)。
DLLMPR.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetGetResourceInformationW(
    NETRESOURCEW* lpNetResource,
    void* lpBuffer,
    DWORD* lpcbBuffer,
    LPWSTR* lplpSystem
);

パラメーター

名前型方向説明
lpNetResourceNETRESOURCEW*in

情報を取得する対象のネットワークリソースを指定する NETRESOURCE 構造体へのポインター。

構造体の lpRemoteName メンバーには、リソースのリモートパス名(通常はユーザーが入力したもの)を指定します。この操作はメモリを多く消費する可能性があり、特に dwType メンバーを指定しない場合に顕著であるため、lpProvider メンバーと dwType メンバーも判明している場合は設定してください。これらのメンバーの値が不明な場合は、NULL を設定します。 NETRESOURCE 構造体のその他のメンバーはすべて無視されます。

lpBuffervoid*out

結果を受け取るバッファーへのポインター。関数が成功して戻ると、バッファーの先頭部分は、入力されたリソースパスのうち、入力リソースの種類に固有のシステム関数ではなく WNet 関数を通じてアクセスされる部分を表す NETRESOURCE 構造体になります。(バッファーの残りの部分には、 NETRESOURCE 構造体のメンバーが指す可変長の文字列が格納されます。)

たとえば、入力されたリモートリソースパスが \server\share\dir1\dir2 の場合、出力される NETRESOURCE 構造体にはリソース \server\share に関する情報が格納されます。パスのうち \dir1\dir2 の部分は ファイル管理関数 を通じてアクセスされます。 NETRESOURCE の lpRemoteName、lpProvider、dwType、dwDisplayType、dwUsage の各メンバーが返され、それ以外のメンバーはすべて NULL に設定されます。

lpRemoteName メンバーは、 WNetEnumResource 関数による列挙で返されるものと同じ構文で返されます。これにより呼び出し元は、 WNetGetResourceInformation に渡したリソースが、別に呼び出した WNetEnumResource によって返されたリソースと同じかどうかを、文字列比較によって判断できます。

lpcbBufferDWORD*inout呼び出し時に lpBuffer バッファーのサイズをバイト単位で指定する場所へのポインター。割り当てるバッファーは、 NETRESOURCE 構造体と、そのメンバーが指す文字列を格納できる十分な大きさである必要があります。バッファーが結果に対して小さすぎる場合、この場所には必要なバッファーサイズが格納され、関数は ERROR_MORE_DATA を返します。
lplpSystemLPWSTR*out

関数が成功した場合、このパラメーターは出力バッファー内の文字列を指します。この文字列は、リソースのうちシステム関数を通じてアクセスされる部分を示します。(これは WNet 関数ではなく、リソースの種類に固有の関数にのみ当てはまります。)

たとえば、入力されたリモートリソース名が \server\share\dir1\dir2 の場合、出力される NETRESOURCE 構造体の lpRemoteName メンバーは \server\share を指します。また、lplpSystem パラメーターは \dir1\dir2 を指します。どちらの文字列も、lpBuffer パラメーターが指すバッファーに格納されます。

戻り値の型: WIN32_ERROR

公式ドキュメント

ネットワークリソースへのリモートパスが指定されると、WNetGetResourceInformation 関数はそのリソースを所有するネットワークプロバイダーを特定し、リソースの種類に関する情報を取得します。(Unicode)

戻り値

関数が成功した場合、戻り値は NO_ERROR です。

関数が失敗した場合、戻り値は システムエラーコード であり、次のいずれかの値になります。

戻り値 説明
ERROR_BAD_NET_NAME
入力された lpRemoteName メンバーが、いずれのネットワークにも存在するネットワークリソースではありません。
ERROR_BAD_DEV_TYPE
入力された dwType メンバーが、lpRemoteName メンバーで指定されたリソースの種類と一致しません。
ERROR_EXTENDED_ERROR
ネットワーク固有のエラーが発生しました。エラーの説明を取得するには WNetGetLastError を呼び出してください。
ERROR_MORE_DATA
lpBuffer パラメーターが指すバッファーが小さすぎます。
ERROR_NO_NETWORK
ネットワークが利用できません。

解説(Remarks)

メモ

winnetwk.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして WNetGetResourceInformation を定義しています。エンコーディング中立のエイリアスの使用とエンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則 を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetGetResourceInformationW(
    NETRESOURCEW* lpNetResource,
    void* lpBuffer,
    DWORD* lpcbBuffer,
    LPWSTR* lplpSystem
);
[DllImport("MPR.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint WNetGetResourceInformationW(
    IntPtr lpNetResource,   // NETRESOURCEW*
    IntPtr lpBuffer,   // void* out
    ref uint lpcbBuffer,   // DWORD* in/out
    IntPtr lplpSystem   // LPWSTR* out
);
<DllImport("MPR.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function WNetGetResourceInformationW(
    lpNetResource As IntPtr,   ' NETRESOURCEW*
    lpBuffer As IntPtr,   ' void* out
    ByRef lpcbBuffer As UInteger,   ' DWORD* in/out
    lplpSystem As IntPtr   ' LPWSTR* out
) As UInteger
End Function
' lpNetResource : NETRESOURCEW*
' lpBuffer : void* out
' lpcbBuffer : DWORD* in/out
' lplpSystem : LPWSTR* out
Declare PtrSafe Function WNetGetResourceInformationW Lib "mpr" ( _
    ByVal lpNetResource As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByRef lpcbBuffer As Long, _
    ByVal lplpSystem As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WNetGetResourceInformationW = ctypes.windll.mpr.WNetGetResourceInformationW
WNetGetResourceInformationW.restype = wintypes.DWORD
WNetGetResourceInformationW.argtypes = [
    ctypes.c_void_p,  # lpNetResource : NETRESOURCEW*
    ctypes.POINTER(None),  # lpBuffer : void* out
    ctypes.POINTER(wintypes.DWORD),  # lpcbBuffer : DWORD* in/out
    ctypes.c_void_p,  # lplpSystem : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPR.dll')
WNetGetResourceInformationW = Fiddle::Function.new(
  lib['WNetGetResourceInformationW'],
  [
    Fiddle::TYPE_VOIDP,  # lpNetResource : NETRESOURCEW*
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* out
    Fiddle::TYPE_VOIDP,  # lpcbBuffer : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # lplpSystem : LPWSTR* out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "mpr")]
extern "system" {
    fn WNetGetResourceInformationW(
        lpNetResource: *mut NETRESOURCEW,  // NETRESOURCEW*
        lpBuffer: *mut (),  // void* out
        lpcbBuffer: *mut u32,  // DWORD* in/out
        lplpSystem: *mut *mut u16  // LPWSTR* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MPR.dll", CharSet = CharSet.Unicode)]
public static extern uint WNetGetResourceInformationW(IntPtr lpNetResource, IntPtr lpBuffer, ref uint lpcbBuffer, IntPtr lplpSystem);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetGetResourceInformationW' -Namespace Win32 -PassThru
# $api::WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
#uselib "MPR.dll"
#func global WNetGetResourceInformationW "WNetGetResourceInformationW" wptr, wptr, wptr, wptr
; WNetGetResourceInformationW varptr(lpNetResource), lpBuffer, varptr(lpcbBuffer), varptr(lplpSystem)   ; 戻り値は stat
; lpNetResource : NETRESOURCEW* -> "wptr"
; lpBuffer : void* out -> "wptr"
; lpcbBuffer : DWORD* in/out -> "wptr"
; lplpSystem : LPWSTR* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MPR.dll"
#cfunc global WNetGetResourceInformationW "WNetGetResourceInformationW" var, sptr, var, var
; res = WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
; lpNetResource : NETRESOURCEW* -> "var"
; lpBuffer : void* out -> "sptr"
; lpcbBuffer : DWORD* in/out -> "var"
; lplpSystem : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR WNetGetResourceInformationW(NETRESOURCEW* lpNetResource, void* lpBuffer, DWORD* lpcbBuffer, LPWSTR* lplpSystem)
#uselib "MPR.dll"
#cfunc global WNetGetResourceInformationW "WNetGetResourceInformationW" var, intptr, var, var
; res = WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
; lpNetResource : NETRESOURCEW* -> "var"
; lpBuffer : void* out -> "intptr"
; lpcbBuffer : DWORD* in/out -> "var"
; lplpSystem : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetGetResourceInformationW = mpr.NewProc("WNetGetResourceInformationW")
)

// lpNetResource (NETRESOURCEW*), lpBuffer (void* out), lpcbBuffer (DWORD* in/out), lplpSystem (LPWSTR* out)
r1, _, err := procWNetGetResourceInformationW.Call(
	uintptr(lpNetResource),
	uintptr(lpBuffer),
	uintptr(lpcbBuffer),
	uintptr(lplpSystem),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetGetResourceInformationW(
  lpNetResource: Pointer;   // NETRESOURCEW*
  lpBuffer: Pointer;   // void* out
  lpcbBuffer: Pointer;   // DWORD* in/out
  lplpSystem: PPWideChar   // LPWSTR* out
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetGetResourceInformationW';
result := DllCall("MPR\WNetGetResourceInformationW"
    , "Ptr", lpNetResource   ; NETRESOURCEW*
    , "Ptr", lpBuffer   ; void* out
    , "Ptr", lpcbBuffer   ; DWORD* in/out
    , "Ptr", lplpSystem   ; LPWSTR* out
    , "UInt")   ; return: WIN32_ERROR
●WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem) = DLL("MPR.dll", "dword WNetGetResourceInformationW(void*, void*, void*, void*)")
# 呼び出し: WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
# lpNetResource : NETRESOURCEW* -> "void*"
# lpBuffer : void* out -> "void*"
# lpcbBuffer : DWORD* in/out -> "void*"
# lplpSystem : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "mpr" fn WNetGetResourceInformationW(
    lpNetResource: [*c]NETRESOURCEW, // NETRESOURCEW*
    lpBuffer: ?*anyopaque, // void* out
    lpcbBuffer: [*c]u32, // DWORD* in/out
    lplpSystem: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc WNetGetResourceInformationW(
    lpNetResource: ptr NETRESOURCEW,  # NETRESOURCEW*
    lpBuffer: pointer,  # void* out
    lpcbBuffer: ptr uint32,  # DWORD* in/out
    lplpSystem: ptr WideCString  # LPWSTR* out
): uint32 {.importc: "WNetGetResourceInformationW", stdcall, dynlib: "MPR.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "mpr");
extern(Windows)
uint WNetGetResourceInformationW(
    NETRESOURCEW* lpNetResource,   // NETRESOURCEW*
    void* lpBuffer,   // void* out
    uint* lpcbBuffer,   // DWORD* in/out
    wchar** lplpSystem   // LPWSTR* out
);
ccall((:WNetGetResourceInformationW, "MPR.dll"), stdcall, UInt32,
      (Ptr{NETRESOURCEW}, Ptr{Cvoid}, Ptr{UInt32}, Ptr{Ptr{UInt16}}),
      lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
# lpNetResource : NETRESOURCEW* -> Ptr{NETRESOURCEW}
# lpBuffer : void* out -> Ptr{Cvoid}
# lpcbBuffer : DWORD* in/out -> Ptr{UInt32}
# lplpSystem : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t WNetGetResourceInformationW(
    void* lpNetResource,
    void* lpBuffer,
    uint32_t* lpcbBuffer,
    uint16_t** lplpSystem);
]]
local mpr = ffi.load("mpr")
-- mpr.WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
-- lpNetResource : NETRESOURCEW*
-- lpBuffer : void* out
-- lpcbBuffer : DWORD* in/out
-- lplpSystem : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('MPR.dll');
const WNetGetResourceInformationW = lib.func('__stdcall', 'WNetGetResourceInformationW', 'uint32_t', ['void *', 'void *', 'uint32_t *', 'void *']);
// WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
// lpNetResource : NETRESOURCEW* -> 'void *'
// lpBuffer : void* out -> 'void *'
// lpcbBuffer : DWORD* in/out -> 'uint32_t *'
// lplpSystem : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MPR.dll", {
  WNetGetResourceInformationW: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
// lpNetResource : NETRESOURCEW* -> "pointer"
// lpBuffer : void* out -> "pointer"
// lpcbBuffer : DWORD* in/out -> "pointer"
// lplpSystem : LPWSTR* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t WNetGetResourceInformationW(
    void* lpNetResource,
    void* lpBuffer,
    uint32_t* lpcbBuffer,
    uint16_t** lplpSystem);
C, "MPR.dll");
// $ffi->WNetGetResourceInformationW(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem);
// lpNetResource : NETRESOURCEW*
// lpBuffer : void* out
// lpcbBuffer : DWORD* in/out
// lplpSystem : LPWSTR* 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 Mpr extends StdCallLibrary {
    Mpr INSTANCE = Native.load("mpr", Mpr.class, W32APIOptions.UNICODE_OPTIONS);
    int WNetGetResourceInformationW(
        Pointer lpNetResource,   // NETRESOURCEW*
        Pointer lpBuffer,   // void* out
        IntByReference lpcbBuffer,   // DWORD* in/out
        PointerByReference lplpSystem   // LPWSTR* out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("mpr")]
lib LibMPR
  fun WNetGetResourceInformationW = WNetGetResourceInformationW(
    lpNetResource : NETRESOURCEW*,   # NETRESOURCEW*
    lpBuffer : Void*,   # void* out
    lpcbBuffer : UInt32*,   # DWORD* in/out
    lplpSystem : UInt16**   # LPWSTR* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WNetGetResourceInformationWNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Pointer<Utf16>>);
typedef WNetGetResourceInformationWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Pointer<Utf16>>);
final WNetGetResourceInformationW = DynamicLibrary.open('MPR.dll')
    .lookupFunction<WNetGetResourceInformationWNative, WNetGetResourceInformationWDart>('WNetGetResourceInformationW');
// lpNetResource : NETRESOURCEW* -> Pointer<Void>
// lpBuffer : void* out -> Pointer<Void>
// lpcbBuffer : DWORD* in/out -> Pointer<Uint32>
// lplpSystem : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WNetGetResourceInformationW(
  lpNetResource: Pointer;   // NETRESOURCEW*
  lpBuffer: Pointer;   // void* out
  lpcbBuffer: Pointer;   // DWORD* in/out
  lplpSystem: PPWideChar   // LPWSTR* out
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetGetResourceInformationW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WNetGetResourceInformationW"
  c_WNetGetResourceInformationW :: Ptr () -> Ptr () -> Ptr Word32 -> Ptr CWString -> IO Word32
-- lpNetResource : NETRESOURCEW* -> Ptr ()
-- lpBuffer : void* out -> Ptr ()
-- lpcbBuffer : DWORD* in/out -> Ptr Word32
-- lplpSystem : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wnetgetresourceinformationw =
  foreign "WNetGetResourceInformationW"
    ((ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr (ptr uint16_t)) @-> returning uint32_t)
(* lpNetResource : NETRESOURCEW* -> (ptr void) *)
(* lpBuffer : void* out -> (ptr void) *)
(* lpcbBuffer : DWORD* in/out -> (ptr uint32_t) *)
(* lplpSystem : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mpr (t "MPR.dll"))
(cffi:use-foreign-library mpr)

(cffi:defcfun ("WNetGetResourceInformationW" wnet-get-resource-information-w :convention :stdcall) :uint32
  (lp-net-resource :pointer)   ; NETRESOURCEW*
  (lp-buffer :pointer)   ; void* out
  (lpcb-buffer :pointer)   ; DWORD* in/out
  (lplp-system :pointer))   ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WNetGetResourceInformationW = Win32::API::More->new('MPR',
    'DWORD WNetGetResourceInformationW(LPVOID lpNetResource, LPVOID lpBuffer, LPVOID lpcbBuffer, LPVOID lplpSystem)');
# my $ret = $WNetGetResourceInformationW->Call($lpNetResource, $lpBuffer, $lpcbBuffer, $lplpSystem);
# lpNetResource : NETRESOURCEW* -> LPVOID
# lpBuffer : void* out -> LPVOID
# lpcbBuffer : DWORD* in/out -> LPVOID
# lplpSystem : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目
使用する型