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

WNetGetResourceInformationA

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

シグネチャ

// MPR.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR WNetGetResourceInformationA(
    NETRESOURCEA* lpNetResource,
    void* lpBuffer,
    DWORD* lpcbBuffer,
    LPSTR* lplpSystem
);

パラメーター

名前型方向説明
lpNetResourceNETRESOURCEA*in

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

構造体の lpRemoteName メンバーには、通常はユーザーが入力したリソースのリモートパス名を指定します。lpProvider メンバーと dwType メンバーも、判明している場合は設定してください。この操作はメモリを大量に消費する可能性があり、特に 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 を返します。
lplpSystemLPSTR*out

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

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

戻り値の型: WIN32_ERROR

公式ドキュメント

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

戻り値

関数が成功した場合、戻り値は 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  (ANSI / -A)
#include <windows.h>

WIN32_ERROR WNetGetResourceInformationA(
    NETRESOURCEA* lpNetResource,
    void* lpBuffer,
    DWORD* lpcbBuffer,
    LPSTR* lplpSystem
);
[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetGetResourceInformationA(
    IntPtr lpNetResource,   // NETRESOURCEA*
    IntPtr lpBuffer,   // void* out
    ref uint lpcbBuffer,   // DWORD* in/out
    IntPtr lplpSystem   // LPSTR* out
);
<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetGetResourceInformationA(
    lpNetResource As IntPtr,   ' NETRESOURCEA*
    lpBuffer As IntPtr,   ' void* out
    ByRef lpcbBuffer As UInteger,   ' DWORD* in/out
    lplpSystem As IntPtr   ' LPSTR* out
) As UInteger
End Function
' lpNetResource : NETRESOURCEA*
' lpBuffer : void* out
' lpcbBuffer : DWORD* in/out
' lplpSystem : LPSTR* out
Declare PtrSafe Function WNetGetResourceInformationA Lib "mpr" ( _
    ByVal lpNetResource As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByRef lpcbBuffer As Long, _
    ByVal lplpSystem As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetGetResourceInformationA = mpr.NewProc("WNetGetResourceInformationA")
)

// lpNetResource (NETRESOURCEA*), lpBuffer (void* out), lpcbBuffer (DWORD* in/out), lplpSystem (LPSTR* out)
r1, _, err := procWNetGetResourceInformationA.Call(
	uintptr(lpNetResource),
	uintptr(lpBuffer),
	uintptr(lpcbBuffer),
	uintptr(lplpSystem),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetGetResourceInformationA(
  lpNetResource: Pointer;   // NETRESOURCEA*
  lpBuffer: Pointer;   // void* out
  lpcbBuffer: Pointer;   // DWORD* in/out
  lplpSystem: PPAnsiChar   // LPSTR* out
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetGetResourceInformationA';
result := DllCall("MPR\WNetGetResourceInformationA"
    , "Ptr", lpNetResource   ; NETRESOURCEA*
    , "Ptr", lpBuffer   ; void* out
    , "Ptr", lpcbBuffer   ; DWORD* in/out
    , "Ptr", lplpSystem   ; LPSTR* out
    , "UInt")   ; return: WIN32_ERROR
●WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem) = DLL("MPR.dll", "dword WNetGetResourceInformationA(void*, void*, void*, void*)")
# 呼び出し: WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
# lpNetResource : NETRESOURCEA* -> "void*"
# lpBuffer : void* out -> "void*"
# lpcbBuffer : DWORD* in/out -> "void*"
# lplpSystem : LPSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mpr" fn WNetGetResourceInformationA(
    lpNetResource: [*c]NETRESOURCEA, // NETRESOURCEA*
    lpBuffer: ?*anyopaque, // void* out
    lpcbBuffer: [*c]u32, // DWORD* in/out
    lplpSystem: [*c][*c]u8 // LPSTR* out
) callconv(std.os.windows.WINAPI) u32;
proc WNetGetResourceInformationA(
    lpNetResource: ptr NETRESOURCEA,  # NETRESOURCEA*
    lpBuffer: pointer,  # void* out
    lpcbBuffer: ptr uint32,  # DWORD* in/out
    lplpSystem: ptr cstring  # LPSTR* out
): uint32 {.importc: "WNetGetResourceInformationA", stdcall, dynlib: "MPR.dll".}
pragma(lib, "mpr");
extern(Windows)
uint WNetGetResourceInformationA(
    NETRESOURCEA* lpNetResource,   // NETRESOURCEA*
    void* lpBuffer,   // void* out
    uint* lpcbBuffer,   // DWORD* in/out
    char** lplpSystem   // LPSTR* out
);
ccall((:WNetGetResourceInformationA, "MPR.dll"), stdcall, UInt32,
      (Ptr{NETRESOURCEA}, Ptr{Cvoid}, Ptr{UInt32}, Ptr{Ptr{UInt8}}),
      lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
# lpNetResource : NETRESOURCEA* -> Ptr{NETRESOURCEA}
# lpBuffer : void* out -> Ptr{Cvoid}
# lpcbBuffer : DWORD* in/out -> Ptr{UInt32}
# lplpSystem : LPSTR* out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t WNetGetResourceInformationA(
    void* lpNetResource,
    void* lpBuffer,
    uint32_t* lpcbBuffer,
    char** lplpSystem);
]]
local mpr = ffi.load("mpr")
-- mpr.WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
-- lpNetResource : NETRESOURCEA*
-- lpBuffer : void* out
-- lpcbBuffer : DWORD* in/out
-- lplpSystem : LPSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MPR.dll');
const WNetGetResourceInformationA = lib.func('__stdcall', 'WNetGetResourceInformationA', 'uint32_t', ['void *', 'void *', 'uint32_t *', 'void *']);
// WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
// lpNetResource : NETRESOURCEA* -> 'void *'
// lpBuffer : void* out -> 'void *'
// lpcbBuffer : DWORD* in/out -> 'uint32_t *'
// lplpSystem : LPSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MPR.dll", {
  WNetGetResourceInformationA: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem)
// lpNetResource : NETRESOURCEA* -> "pointer"
// lpBuffer : void* out -> "pointer"
// lpcbBuffer : DWORD* in/out -> "pointer"
// lplpSystem : LPSTR* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t WNetGetResourceInformationA(
    void* lpNetResource,
    void* lpBuffer,
    uint32_t* lpcbBuffer,
    char** lplpSystem);
C, "MPR.dll");
// $ffi->WNetGetResourceInformationA(lpNetResource, lpBuffer, lpcbBuffer, lplpSystem);
// lpNetResource : NETRESOURCEA*
// lpBuffer : void* out
// lpcbBuffer : DWORD* in/out
// lplpSystem : LPSTR* 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.ASCII_OPTIONS);
    int WNetGetResourceInformationA(
        Pointer lpNetResource,   // NETRESOURCEA*
        Pointer lpBuffer,   // void* out
        IntByReference lpcbBuffer,   // DWORD* in/out
        PointerByReference lplpSystem   // LPSTR* out
    );
}
@[Link("mpr")]
lib LibMPR
  fun WNetGetResourceInformationA = WNetGetResourceInformationA(
    lpNetResource : NETRESOURCEA*,   # NETRESOURCEA*
    lpBuffer : Void*,   # void* out
    lpcbBuffer : UInt32*,   # DWORD* in/out
    lplpSystem : UInt8**   # LPSTR* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

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

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

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

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

関連項目

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