ホーム › NetworkManagement.WNet › WNetGetNetworkInformationA
WNetGetNetworkInformationA
関数指定プロバイダーのネットワーク情報を取得する(ANSI版)。
シグネチャ
// MPR.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR WNetGetNetworkInformationA(
LPCSTR lpProvider,
NETINFOSTRUCT* lpNetInfoStruct
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpProvider | LPCSTR | in |
| lpNetInfoStruct | NETINFOSTRUCT* | out |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// MPR.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR WNetGetNetworkInformationA(
LPCSTR lpProvider,
NETINFOSTRUCT* lpNetInfoStruct
);[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetGetNetworkInformationA(
[MarshalAs(UnmanagedType.LPStr)] string lpProvider, // LPCSTR
IntPtr lpNetInfoStruct // NETINFOSTRUCT* out
);<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetGetNetworkInformationA(
<MarshalAs(UnmanagedType.LPStr)> lpProvider As String, ' LPCSTR
lpNetInfoStruct As IntPtr ' NETINFOSTRUCT* out
) As UInteger
End Function' lpProvider : LPCSTR
' lpNetInfoStruct : NETINFOSTRUCT* out
Declare PtrSafe Function WNetGetNetworkInformationA Lib "mpr" ( _
ByVal lpProvider As String, _
ByVal lpNetInfoStruct As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WNetGetNetworkInformationA = ctypes.windll.mpr.WNetGetNetworkInformationA
WNetGetNetworkInformationA.restype = wintypes.DWORD
WNetGetNetworkInformationA.argtypes = [
wintypes.LPCSTR, # lpProvider : LPCSTR
ctypes.c_void_p, # lpNetInfoStruct : NETINFOSTRUCT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MPR.dll')
WNetGetNetworkInformationA = Fiddle::Function.new(
lib['WNetGetNetworkInformationA'],
[
Fiddle::TYPE_VOIDP, # lpProvider : LPCSTR
Fiddle::TYPE_VOIDP, # lpNetInfoStruct : NETINFOSTRUCT* out
],
-Fiddle::TYPE_INT)#[link(name = "mpr")]
extern "system" {
fn WNetGetNetworkInformationA(
lpProvider: *const u8, // LPCSTR
lpNetInfoStruct: *mut NETINFOSTRUCT // NETINFOSTRUCT* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MPR.dll", CharSet = CharSet.Ansi)]
public static extern uint WNetGetNetworkInformationA([MarshalAs(UnmanagedType.LPStr)] string lpProvider, IntPtr lpNetInfoStruct);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetGetNetworkInformationA' -Namespace Win32 -PassThru
# $api::WNetGetNetworkInformationA(lpProvider, lpNetInfoStruct)#uselib "MPR.dll"
#func global WNetGetNetworkInformationA "WNetGetNetworkInformationA" sptr, sptr
; WNetGetNetworkInformationA lpProvider, varptr(lpNetInfoStruct) ; 戻り値は stat
; lpProvider : LPCSTR -> "sptr"
; lpNetInfoStruct : NETINFOSTRUCT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MPR.dll" #cfunc global WNetGetNetworkInformationA "WNetGetNetworkInformationA" str, var ; res = WNetGetNetworkInformationA(lpProvider, lpNetInfoStruct) ; lpProvider : LPCSTR -> "str" ; lpNetInfoStruct : NETINFOSTRUCT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MPR.dll" #cfunc global WNetGetNetworkInformationA "WNetGetNetworkInformationA" str, sptr ; res = WNetGetNetworkInformationA(lpProvider, varptr(lpNetInfoStruct)) ; lpProvider : LPCSTR -> "str" ; lpNetInfoStruct : NETINFOSTRUCT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR WNetGetNetworkInformationA(LPCSTR lpProvider, NETINFOSTRUCT* lpNetInfoStruct) #uselib "MPR.dll" #cfunc global WNetGetNetworkInformationA "WNetGetNetworkInformationA" str, var ; res = WNetGetNetworkInformationA(lpProvider, lpNetInfoStruct) ; lpProvider : LPCSTR -> "str" ; lpNetInfoStruct : NETINFOSTRUCT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR WNetGetNetworkInformationA(LPCSTR lpProvider, NETINFOSTRUCT* lpNetInfoStruct) #uselib "MPR.dll" #cfunc global WNetGetNetworkInformationA "WNetGetNetworkInformationA" str, intptr ; res = WNetGetNetworkInformationA(lpProvider, varptr(lpNetInfoStruct)) ; lpProvider : LPCSTR -> "str" ; lpNetInfoStruct : NETINFOSTRUCT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mpr = windows.NewLazySystemDLL("MPR.dll")
procWNetGetNetworkInformationA = mpr.NewProc("WNetGetNetworkInformationA")
)
// lpProvider (LPCSTR), lpNetInfoStruct (NETINFOSTRUCT* out)
r1, _, err := procWNetGetNetworkInformationA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpProvider))),
uintptr(lpNetInfoStruct),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction WNetGetNetworkInformationA(
lpProvider: PAnsiChar; // LPCSTR
lpNetInfoStruct: Pointer // NETINFOSTRUCT* out
): DWORD; stdcall;
external 'MPR.dll' name 'WNetGetNetworkInformationA';result := DllCall("MPR\WNetGetNetworkInformationA"
, "AStr", lpProvider ; LPCSTR
, "Ptr", lpNetInfoStruct ; NETINFOSTRUCT* out
, "UInt") ; return: WIN32_ERROR●WNetGetNetworkInformationA(lpProvider, lpNetInfoStruct) = DLL("MPR.dll", "dword WNetGetNetworkInformationA(char*, void*)")
# 呼び出し: WNetGetNetworkInformationA(lpProvider, lpNetInfoStruct)
# lpProvider : LPCSTR -> "char*"
# lpNetInfoStruct : NETINFOSTRUCT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。