ホーム › NetworkManagement.WNet › WNetGetUniversalNameW
WNetGetUniversalNameW
関数ローカルパスからUNC形式の汎用名を取得する(Unicode版)。
シグネチャ
// MPR.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR WNetGetUniversalNameW(
LPCWSTR lpLocalPath,
UNC_INFO_LEVEL dwInfoLevel,
void* lpBuffer,
DWORD* lpBufferSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpLocalPath | LPCWSTR | in |
| dwInfoLevel | UNC_INFO_LEVEL | in |
| lpBuffer | void* | out |
| lpBufferSize | DWORD* | inout |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// MPR.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR WNetGetUniversalNameW(
LPCWSTR lpLocalPath,
UNC_INFO_LEVEL dwInfoLevel,
void* lpBuffer,
DWORD* lpBufferSize
);[DllImport("MPR.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint WNetGetUniversalNameW(
[MarshalAs(UnmanagedType.LPWStr)] string lpLocalPath, // LPCWSTR
uint dwInfoLevel, // UNC_INFO_LEVEL
IntPtr lpBuffer, // void* out
ref uint lpBufferSize // DWORD* in/out
);<DllImport("MPR.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function WNetGetUniversalNameW(
<MarshalAs(UnmanagedType.LPWStr)> lpLocalPath As String, ' LPCWSTR
dwInfoLevel As UInteger, ' UNC_INFO_LEVEL
lpBuffer As IntPtr, ' void* out
ByRef lpBufferSize As UInteger ' DWORD* in/out
) As UInteger
End Function' lpLocalPath : LPCWSTR
' dwInfoLevel : UNC_INFO_LEVEL
' lpBuffer : void* out
' lpBufferSize : DWORD* in/out
Declare PtrSafe Function WNetGetUniversalNameW Lib "mpr" ( _
ByVal lpLocalPath As LongPtr, _
ByVal dwInfoLevel As Long, _
ByVal lpBuffer As LongPtr, _
ByRef lpBufferSize As Long) 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
WNetGetUniversalNameW = ctypes.windll.mpr.WNetGetUniversalNameW
WNetGetUniversalNameW.restype = wintypes.DWORD
WNetGetUniversalNameW.argtypes = [
wintypes.LPCWSTR, # lpLocalPath : LPCWSTR
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')
WNetGetUniversalNameW = Fiddle::Function.new(
lib['WNetGetUniversalNameW'],
[
Fiddle::TYPE_VOIDP, # lpLocalPath : LPCWSTR
-Fiddle::TYPE_INT, # dwInfoLevel : UNC_INFO_LEVEL
Fiddle::TYPE_VOIDP, # lpBuffer : void* out
Fiddle::TYPE_VOIDP, # lpBufferSize : DWORD* in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "mpr")]
extern "system" {
fn WNetGetUniversalNameW(
lpLocalPath: *const u16, // LPCWSTR
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.Unicode)]
public static extern uint WNetGetUniversalNameW([MarshalAs(UnmanagedType.LPWStr)] string lpLocalPath, uint dwInfoLevel, IntPtr lpBuffer, ref uint lpBufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetGetUniversalNameW' -Namespace Win32 -PassThru
# $api::WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)#uselib "MPR.dll"
#func global WNetGetUniversalNameW "WNetGetUniversalNameW" wptr, wptr, wptr, wptr
; WNetGetUniversalNameW lpLocalPath, dwInfoLevel, lpBuffer, varptr(lpBufferSize) ; 戻り値は stat
; lpLocalPath : LPCWSTR -> "wptr"
; dwInfoLevel : UNC_INFO_LEVEL -> "wptr"
; lpBuffer : void* out -> "wptr"
; lpBufferSize : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MPR.dll" #cfunc global WNetGetUniversalNameW "WNetGetUniversalNameW" wstr, int, sptr, var ; res = WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize) ; lpLocalPath : LPCWSTR -> "wstr" ; dwInfoLevel : UNC_INFO_LEVEL -> "int" ; lpBuffer : void* out -> "sptr" ; lpBufferSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MPR.dll" #cfunc global WNetGetUniversalNameW "WNetGetUniversalNameW" wstr, int, sptr, sptr ; res = WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, varptr(lpBufferSize)) ; lpLocalPath : LPCWSTR -> "wstr" ; dwInfoLevel : UNC_INFO_LEVEL -> "int" ; lpBuffer : void* out -> "sptr" ; lpBufferSize : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR WNetGetUniversalNameW(LPCWSTR lpLocalPath, UNC_INFO_LEVEL dwInfoLevel, void* lpBuffer, DWORD* lpBufferSize) #uselib "MPR.dll" #cfunc global WNetGetUniversalNameW "WNetGetUniversalNameW" wstr, int, intptr, var ; res = WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize) ; lpLocalPath : LPCWSTR -> "wstr" ; dwInfoLevel : UNC_INFO_LEVEL -> "int" ; lpBuffer : void* out -> "intptr" ; lpBufferSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR WNetGetUniversalNameW(LPCWSTR lpLocalPath, UNC_INFO_LEVEL dwInfoLevel, void* lpBuffer, DWORD* lpBufferSize) #uselib "MPR.dll" #cfunc global WNetGetUniversalNameW "WNetGetUniversalNameW" wstr, int, intptr, intptr ; res = WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, varptr(lpBufferSize)) ; lpLocalPath : LPCWSTR -> "wstr" ; dwInfoLevel : UNC_INFO_LEVEL -> "int" ; lpBuffer : void* out -> "intptr" ; lpBufferSize : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mpr = windows.NewLazySystemDLL("MPR.dll")
procWNetGetUniversalNameW = mpr.NewProc("WNetGetUniversalNameW")
)
// lpLocalPath (LPCWSTR), dwInfoLevel (UNC_INFO_LEVEL), lpBuffer (void* out), lpBufferSize (DWORD* in/out)
r1, _, err := procWNetGetUniversalNameW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocalPath))),
uintptr(dwInfoLevel),
uintptr(lpBuffer),
uintptr(lpBufferSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction WNetGetUniversalNameW(
lpLocalPath: PWideChar; // LPCWSTR
dwInfoLevel: DWORD; // UNC_INFO_LEVEL
lpBuffer: Pointer; // void* out
lpBufferSize: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'MPR.dll' name 'WNetGetUniversalNameW';result := DllCall("MPR\WNetGetUniversalNameW"
, "WStr", lpLocalPath ; LPCWSTR
, "UInt", dwInfoLevel ; UNC_INFO_LEVEL
, "Ptr", lpBuffer ; void* out
, "Ptr", lpBufferSize ; DWORD* in/out
, "UInt") ; return: WIN32_ERROR●WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize) = DLL("MPR.dll", "dword WNetGetUniversalNameW(char*, dword, void*, void*)")
# 呼び出し: WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
# lpLocalPath : LPCWSTR -> "char*"
# dwInfoLevel : UNC_INFO_LEVEL -> "dword"
# lpBuffer : void* out -> "void*"
# lpBufferSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。