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

WNetGetUniversalNameA

関数
ローカルパスからUNC形式の汎用名を取得する(ANSI版)。
DLLMPR.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR WNetGetUniversalNameA(
    LPCSTR lpLocalPath,
    UNC_INFO_LEVEL dwInfoLevel,
    void* lpBuffer,
    DWORD* lpBufferSize
);

パラメーター

名前方向
lpLocalPathLPCSTRin
dwInfoLevelUNC_INFO_LEVELin
lpBuffervoid*out
lpBufferSizeDWORD*inout

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR WNetGetUniversalNameA(
    LPCSTR lpLocalPath,
    UNC_INFO_LEVEL dwInfoLevel,
    void* lpBuffer,
    DWORD* lpBufferSize
);
[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetGetUniversalNameA(
    [MarshalAs(UnmanagedType.LPStr)] string lpLocalPath,   // LPCSTR
    uint dwInfoLevel,   // UNC_INFO_LEVEL
    IntPtr lpBuffer,   // void* out
    ref uint lpBufferSize   // DWORD* in/out
);
<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetGetUniversalNameA(
    <MarshalAs(UnmanagedType.LPStr)> lpLocalPath As String,   ' LPCSTR
    dwInfoLevel As UInteger,   ' UNC_INFO_LEVEL
    lpBuffer As IntPtr,   ' void* out
    ByRef lpBufferSize As UInteger   ' DWORD* in/out
) As UInteger
End Function
' lpLocalPath : LPCSTR
' dwInfoLevel : UNC_INFO_LEVEL
' lpBuffer : void* out
' lpBufferSize : DWORD* in/out
Declare PtrSafe Function WNetGetUniversalNameA Lib "mpr" ( _
    ByVal lpLocalPath As String, _
    ByVal dwInfoLevel As Long, _
    ByVal lpBuffer As LongPtr, _
    ByRef lpBufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WNetGetUniversalNameA = ctypes.windll.mpr.WNetGetUniversalNameA
WNetGetUniversalNameA.restype = wintypes.DWORD
WNetGetUniversalNameA.argtypes = [
    wintypes.LPCSTR,  # lpLocalPath : LPCSTR
    wintypes.DWORD,  # dwInfoLevel : UNC_INFO_LEVEL
    ctypes.POINTER(None),  # lpBuffer : void* out
    ctypes.POINTER(wintypes.DWORD),  # lpBufferSize : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPR.dll')
WNetGetUniversalNameA = Fiddle::Function.new(
  lib['WNetGetUniversalNameA'],
  [
    Fiddle::TYPE_VOIDP,  # lpLocalPath : LPCSTR
    -Fiddle::TYPE_INT,  # dwInfoLevel : UNC_INFO_LEVEL
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* out
    Fiddle::TYPE_VOIDP,  # lpBufferSize : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "mpr")]
extern "system" {
    fn WNetGetUniversalNameA(
        lpLocalPath: *const u8,  // LPCSTR
        dwInfoLevel: u32,  // UNC_INFO_LEVEL
        lpBuffer: *mut (),  // void* out
        lpBufferSize: *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 WNetGetUniversalNameA([MarshalAs(UnmanagedType.LPStr)] string lpLocalPath, uint dwInfoLevel, IntPtr lpBuffer, ref uint lpBufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetGetUniversalNameA' -Namespace Win32 -PassThru
# $api::WNetGetUniversalNameA(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
#uselib "MPR.dll"
#func global WNetGetUniversalNameA "WNetGetUniversalNameA" sptr, sptr, sptr, sptr
; WNetGetUniversalNameA lpLocalPath, dwInfoLevel, lpBuffer, varptr(lpBufferSize)   ; 戻り値は stat
; lpLocalPath : LPCSTR -> "sptr"
; dwInfoLevel : UNC_INFO_LEVEL -> "sptr"
; lpBuffer : void* out -> "sptr"
; lpBufferSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MPR.dll"
#cfunc global WNetGetUniversalNameA "WNetGetUniversalNameA" str, int, sptr, var
; res = WNetGetUniversalNameA(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
; lpLocalPath : LPCSTR -> "str"
; dwInfoLevel : UNC_INFO_LEVEL -> "int"
; lpBuffer : void* out -> "sptr"
; lpBufferSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR WNetGetUniversalNameA(LPCSTR lpLocalPath, UNC_INFO_LEVEL dwInfoLevel, void* lpBuffer, DWORD* lpBufferSize)
#uselib "MPR.dll"
#cfunc global WNetGetUniversalNameA "WNetGetUniversalNameA" str, int, intptr, var
; res = WNetGetUniversalNameA(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
; lpLocalPath : LPCSTR -> "str"
; dwInfoLevel : UNC_INFO_LEVEL -> "int"
; lpBuffer : void* out -> "intptr"
; lpBufferSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetGetUniversalNameA = mpr.NewProc("WNetGetUniversalNameA")
)

// lpLocalPath (LPCSTR), dwInfoLevel (UNC_INFO_LEVEL), lpBuffer (void* out), lpBufferSize (DWORD* in/out)
r1, _, err := procWNetGetUniversalNameA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpLocalPath))),
	uintptr(dwInfoLevel),
	uintptr(lpBuffer),
	uintptr(lpBufferSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetGetUniversalNameA(
  lpLocalPath: PAnsiChar;   // LPCSTR
  dwInfoLevel: DWORD;   // UNC_INFO_LEVEL
  lpBuffer: Pointer;   // void* out
  lpBufferSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetGetUniversalNameA';
result := DllCall("MPR\WNetGetUniversalNameA"
    , "AStr", lpLocalPath   ; LPCSTR
    , "UInt", dwInfoLevel   ; UNC_INFO_LEVEL
    , "Ptr", lpBuffer   ; void* out
    , "Ptr", lpBufferSize   ; DWORD* in/out
    , "UInt")   ; return: WIN32_ERROR
●WNetGetUniversalNameA(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize) = DLL("MPR.dll", "dword WNetGetUniversalNameA(char*, dword, void*, void*)")
# 呼び出し: WNetGetUniversalNameA(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
# lpLocalPath : LPCSTR -> "char*"
# dwInfoLevel : UNC_INFO_LEVEL -> "dword"
# lpBuffer : void* out -> "void*"
# lpBufferSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。