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