ホーム › 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 | UNC形式に変換する対象のローカルパスのワイド文字列。 |
| dwInfoLevel | UNC_INFO_LEVEL | in | 取得する情報のレベル(UNIVERSAL_NAME_INFO/REMOTE_NAME_INFO)。 |
| lpBuffer | void* | out | 変換結果のユニバーサル名情報を受け取るバッファ。 |
| lpBufferSize | DWORD* | inout | lpBufferのバイト数を入出力で渡し、不足時は必要量を受け取る。 |
戻り値の型: 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 版の利用を推奨。const std = @import("std");
extern "mpr" fn WNetGetUniversalNameW(
lpLocalPath: [*c]const u16, // LPCWSTR
dwInfoLevel: u32, // UNC_INFO_LEVEL
lpBuffer: ?*anyopaque, // void* out
lpBufferSize: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc WNetGetUniversalNameW(
lpLocalPath: WideCString, # LPCWSTR
dwInfoLevel: uint32, # UNC_INFO_LEVEL
lpBuffer: pointer, # void* out
lpBufferSize: ptr uint32 # DWORD* in/out
): uint32 {.importc: "WNetGetUniversalNameW", stdcall, dynlib: "MPR.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "mpr");
extern(Windows)
uint WNetGetUniversalNameW(
const(wchar)* lpLocalPath, // LPCWSTR
uint dwInfoLevel, // UNC_INFO_LEVEL
void* lpBuffer, // void* out
uint* lpBufferSize // DWORD* in/out
);ccall((:WNetGetUniversalNameW, "MPR.dll"), stdcall, UInt32,
(Cwstring, UInt32, Ptr{Cvoid}, Ptr{UInt32}),
lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
# lpLocalPath : LPCWSTR -> Cwstring
# dwInfoLevel : UNC_INFO_LEVEL -> UInt32
# lpBuffer : void* out -> Ptr{Cvoid}
# lpBufferSize : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t WNetGetUniversalNameW(
const uint16_t* lpLocalPath,
uint32_t dwInfoLevel,
void* lpBuffer,
uint32_t* lpBufferSize);
]]
local mpr = ffi.load("mpr")
-- mpr.WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
-- lpLocalPath : LPCWSTR
-- dwInfoLevel : UNC_INFO_LEVEL
-- lpBuffer : void* out
-- lpBufferSize : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('MPR.dll');
const WNetGetUniversalNameW = lib.func('__stdcall', 'WNetGetUniversalNameW', 'uint32_t', ['str16', 'uint32_t', 'void *', 'uint32_t *']);
// WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
// lpLocalPath : LPCWSTR -> 'str16'
// dwInfoLevel : UNC_INFO_LEVEL -> 'uint32_t'
// lpBuffer : void* out -> 'void *'
// lpBufferSize : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MPR.dll", {
WNetGetUniversalNameW: { parameters: ["buffer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize)
// lpLocalPath : LPCWSTR -> "buffer"
// dwInfoLevel : UNC_INFO_LEVEL -> "u32"
// lpBuffer : void* out -> "pointer"
// lpBufferSize : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t WNetGetUniversalNameW(
const uint16_t* lpLocalPath,
uint32_t dwInfoLevel,
void* lpBuffer,
uint32_t* lpBufferSize);
C, "MPR.dll");
// $ffi->WNetGetUniversalNameW(lpLocalPath, dwInfoLevel, lpBuffer, lpBufferSize);
// lpLocalPath : LPCWSTR
// dwInfoLevel : UNC_INFO_LEVEL
// lpBuffer : void* out
// lpBufferSize : DWORD* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Mpr extends StdCallLibrary {
Mpr INSTANCE = Native.load("mpr", Mpr.class, W32APIOptions.UNICODE_OPTIONS);
int WNetGetUniversalNameW(
WString lpLocalPath, // LPCWSTR
int dwInfoLevel, // UNC_INFO_LEVEL
Pointer lpBuffer, // void* out
IntByReference lpBufferSize // DWORD* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("mpr")]
lib LibMPR
fun WNetGetUniversalNameW = WNetGetUniversalNameW(
lpLocalPath : UInt16*, # LPCWSTR
dwInfoLevel : UInt32, # UNC_INFO_LEVEL
lpBuffer : Void*, # void* out
lpBufferSize : UInt32* # DWORD* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WNetGetUniversalNameWNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef WNetGetUniversalNameWDart = int Function(Pointer<Utf16>, int, Pointer<Void>, Pointer<Uint32>);
final WNetGetUniversalNameW = DynamicLibrary.open('MPR.dll')
.lookupFunction<WNetGetUniversalNameWNative, WNetGetUniversalNameWDart>('WNetGetUniversalNameW');
// lpLocalPath : LPCWSTR -> Pointer<Utf16>
// dwInfoLevel : UNC_INFO_LEVEL -> Uint32
// lpBuffer : void* out -> Pointer<Void>
// lpBufferSize : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WNetGetUniversalNameW"
c_WNetGetUniversalNameW :: CWString -> Word32 -> Ptr () -> Ptr Word32 -> IO Word32
-- lpLocalPath : LPCWSTR -> CWString
-- dwInfoLevel : UNC_INFO_LEVEL -> Word32
-- lpBuffer : void* out -> Ptr ()
-- lpBufferSize : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wnetgetuniversalnamew =
foreign "WNetGetUniversalNameW"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning uint32_t)
(* lpLocalPath : LPCWSTR -> (ptr uint16_t) *)
(* dwInfoLevel : UNC_INFO_LEVEL -> uint32_t *)
(* lpBuffer : void* out -> (ptr void) *)
(* lpBufferSize : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mpr (t "MPR.dll"))
(cffi:use-foreign-library mpr)
(cffi:defcfun ("WNetGetUniversalNameW" wnet-get-universal-name-w :convention :stdcall) :uint32
(lp-local-path (:string :encoding :utf-16le)) ; LPCWSTR
(dw-info-level :uint32) ; UNC_INFO_LEVEL
(lp-buffer :pointer) ; void* out
(lp-buffer-size :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WNetGetUniversalNameW = Win32::API::More->new('MPR',
'DWORD WNetGetUniversalNameW(LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPVOID lpBufferSize)');
# my $ret = $WNetGetUniversalNameW->Call($lpLocalPath, $dwInfoLevel, $lpBuffer, $lpBufferSize);
# lpLocalPath : LPCWSTR -> LPCWSTR
# dwInfoLevel : UNC_INFO_LEVEL -> DWORD
# lpBuffer : void* out -> LPVOID
# lpBufferSize : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f WNetGetUniversalNameA (ANSI版) — ローカルパスからUNC形式の汎用名を取得する(ANSI版)。