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

WNetGetNetworkInformationW

関数
指定プロバイダーのネットワーク情報を取得する(Unicode版)。
DLLMPR.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR WNetGetNetworkInformationW(
    LPCWSTR lpProvider,
    NETINFOSTRUCT* lpNetInfoStruct
);

パラメーター

名前方向
lpProviderLPCWSTRin
lpNetInfoStructNETINFOSTRUCT*out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR WNetGetNetworkInformationW(
    LPCWSTR lpProvider,
    NETINFOSTRUCT* lpNetInfoStruct
);
[DllImport("MPR.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint WNetGetNetworkInformationW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpProvider,   // LPCWSTR
    IntPtr lpNetInfoStruct   // NETINFOSTRUCT* out
);
<DllImport("MPR.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function WNetGetNetworkInformationW(
    <MarshalAs(UnmanagedType.LPWStr)> lpProvider As String,   ' LPCWSTR
    lpNetInfoStruct As IntPtr   ' NETINFOSTRUCT* out
) As UInteger
End Function
' lpProvider : LPCWSTR
' lpNetInfoStruct : NETINFOSTRUCT* out
Declare PtrSafe Function WNetGetNetworkInformationW Lib "mpr" ( _
    ByVal lpProvider As LongPtr, _
    ByVal lpNetInfoStruct 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

WNetGetNetworkInformationW = ctypes.windll.mpr.WNetGetNetworkInformationW
WNetGetNetworkInformationW.restype = wintypes.DWORD
WNetGetNetworkInformationW.argtypes = [
    wintypes.LPCWSTR,  # lpProvider : LPCWSTR
    ctypes.c_void_p,  # lpNetInfoStruct : NETINFOSTRUCT* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetGetNetworkInformationW = mpr.NewProc("WNetGetNetworkInformationW")
)

// lpProvider (LPCWSTR), lpNetInfoStruct (NETINFOSTRUCT* out)
r1, _, err := procWNetGetNetworkInformationW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpProvider))),
	uintptr(lpNetInfoStruct),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetGetNetworkInformationW(
  lpProvider: PWideChar;   // LPCWSTR
  lpNetInfoStruct: Pointer   // NETINFOSTRUCT* out
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetGetNetworkInformationW';
result := DllCall("MPR\WNetGetNetworkInformationW"
    , "WStr", lpProvider   ; LPCWSTR
    , "Ptr", lpNetInfoStruct   ; NETINFOSTRUCT* out
    , "UInt")   ; return: WIN32_ERROR
●WNetGetNetworkInformationW(lpProvider, lpNetInfoStruct) = DLL("MPR.dll", "dword WNetGetNetworkInformationW(char*, void*)")
# 呼び出し: WNetGetNetworkInformationW(lpProvider, lpNetInfoStruct)
# lpProvider : LPCWSTR -> "char*"
# lpNetInfoStruct : NETINFOSTRUCT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。