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

DavGetUNCFromHTTPPath

関数
WebDAVのHTTP URLを対応するUNCパスに変換する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// NETAPI32.dll
#include <windows.h>

DWORD DavGetUNCFromHTTPPath(
    LPCWSTR Url,
    LPWSTR UncPath,   // optional
    DWORD* lpSize
);

パラメーター

名前方向説明
UrlLPCWSTRin変換元のHTTP/WebDAV URL文字列。
UncPathLPWSTRoutoptional変換結果のUNCパスを受け取る呼び出し側確保のバッファ。
lpSizeDWORD*inout入力でバッファ容量(文字数)、出力で必要サイズを受け渡すDWORDポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

// NETAPI32.dll
#include <windows.h>

DWORD DavGetUNCFromHTTPPath(
    LPCWSTR Url,
    LPWSTR UncPath,   // optional
    DWORD* lpSize
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint DavGetUNCFromHTTPPath(
    [MarshalAs(UnmanagedType.LPWStr)] string Url,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder UncPath,   // LPWSTR optional, out
    ref uint lpSize   // DWORD* in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function DavGetUNCFromHTTPPath(
    <MarshalAs(UnmanagedType.LPWStr)> Url As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> UncPath As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef lpSize As UInteger   ' DWORD* in/out
) As UInteger
End Function
' Url : LPCWSTR
' UncPath : LPWSTR optional, out
' lpSize : DWORD* in/out
Declare PtrSafe Function DavGetUNCFromHTTPPath Lib "netapi32" ( _
    ByVal Url As LongPtr, _
    ByVal UncPath As LongPtr, _
    ByRef lpSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DavGetUNCFromHTTPPath = ctypes.windll.netapi32.DavGetUNCFromHTTPPath
DavGetUNCFromHTTPPath.restype = wintypes.DWORD
DavGetUNCFromHTTPPath.argtypes = [
    wintypes.LPCWSTR,  # Url : LPCWSTR
    wintypes.LPWSTR,  # UncPath : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpSize : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
DavGetUNCFromHTTPPath = Fiddle::Function.new(
  lib['DavGetUNCFromHTTPPath'],
  [
    Fiddle::TYPE_VOIDP,  # Url : LPCWSTR
    Fiddle::TYPE_VOIDP,  # UncPath : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # lpSize : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn DavGetUNCFromHTTPPath(
        Url: *const u16,  // LPCWSTR
        UncPath: *mut u16,  // LPWSTR optional, out
        lpSize: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint DavGetUNCFromHTTPPath([MarshalAs(UnmanagedType.LPWStr)] string Url, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder UncPath, ref uint lpSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_DavGetUNCFromHTTPPath' -Namespace Win32 -PassThru
# $api::DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
#uselib "NETAPI32.dll"
#func global DavGetUNCFromHTTPPath "DavGetUNCFromHTTPPath" sptr, sptr, sptr
; DavGetUNCFromHTTPPath Url, varptr(UncPath), varptr(lpSize)   ; 戻り値は stat
; Url : LPCWSTR -> "sptr"
; UncPath : LPWSTR optional, out -> "sptr"
; lpSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global DavGetUNCFromHTTPPath "DavGetUNCFromHTTPPath" wstr, var, var
; res = DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
; Url : LPCWSTR -> "wstr"
; UncPath : LPWSTR optional, out -> "var"
; lpSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DavGetUNCFromHTTPPath(LPCWSTR Url, LPWSTR UncPath, DWORD* lpSize)
#uselib "NETAPI32.dll"
#cfunc global DavGetUNCFromHTTPPath "DavGetUNCFromHTTPPath" wstr, var, var
; res = DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
; Url : LPCWSTR -> "wstr"
; UncPath : LPWSTR optional, out -> "var"
; lpSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procDavGetUNCFromHTTPPath = netapi32.NewProc("DavGetUNCFromHTTPPath")
)

// Url (LPCWSTR), UncPath (LPWSTR optional, out), lpSize (DWORD* in/out)
r1, _, err := procDavGetUNCFromHTTPPath.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Url))),
	uintptr(UncPath),
	uintptr(lpSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DavGetUNCFromHTTPPath(
  Url: PWideChar;   // LPCWSTR
  UncPath: PWideChar;   // LPWSTR optional, out
  lpSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DavGetUNCFromHTTPPath';
result := DllCall("NETAPI32\DavGetUNCFromHTTPPath"
    , "WStr", Url   ; LPCWSTR
    , "Ptr", UncPath   ; LPWSTR optional, out
    , "Ptr", lpSize   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●DavGetUNCFromHTTPPath(Url, UncPath, lpSize) = DLL("NETAPI32.dll", "dword DavGetUNCFromHTTPPath(char*, char*, void*)")
# 呼び出し: DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
# Url : LPCWSTR -> "char*"
# UncPath : LPWSTR optional, out -> "char*"
# lpSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn DavGetUNCFromHTTPPath(
    Url: [*c]const u16, // LPCWSTR
    UncPath: [*c]u16, // LPWSTR optional, out
    lpSize: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc DavGetUNCFromHTTPPath(
    Url: WideCString,  # LPCWSTR
    UncPath: ptr uint16,  # LPWSTR optional, out
    lpSize: ptr uint32  # DWORD* in/out
): uint32 {.importc: "DavGetUNCFromHTTPPath", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint DavGetUNCFromHTTPPath(
    const(wchar)* Url,   // LPCWSTR
    wchar* UncPath,   // LPWSTR optional, out
    uint* lpSize   // DWORD* in/out
);
ccall((:DavGetUNCFromHTTPPath, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Ptr{UInt16}, Ptr{UInt32}),
      Url, UncPath, lpSize)
# Url : LPCWSTR -> Cwstring
# UncPath : LPWSTR optional, out -> Ptr{UInt16}
# lpSize : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t DavGetUNCFromHTTPPath(
    const uint16_t* Url,
    uint16_t* UncPath,
    uint32_t* lpSize);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
-- Url : LPCWSTR
-- UncPath : LPWSTR optional, out
-- lpSize : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const DavGetUNCFromHTTPPath = lib.func('__stdcall', 'DavGetUNCFromHTTPPath', 'uint32_t', ['str16', 'uint16_t *', 'uint32_t *']);
// DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
// Url : LPCWSTR -> 'str16'
// UncPath : LPWSTR optional, out -> 'uint16_t *'
// lpSize : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  DavGetUNCFromHTTPPath: { parameters: ["buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.DavGetUNCFromHTTPPath(Url, UncPath, lpSize)
// Url : LPCWSTR -> "buffer"
// UncPath : LPWSTR optional, out -> "buffer"
// lpSize : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t DavGetUNCFromHTTPPath(
    const uint16_t* Url,
    uint16_t* UncPath,
    uint32_t* lpSize);
C, "NETAPI32.dll");
// $ffi->DavGetUNCFromHTTPPath(Url, UncPath, lpSize);
// Url : LPCWSTR
// UncPath : LPWSTR optional, out
// lpSize : 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 Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int DavGetUNCFromHTTPPath(
        WString Url,   // LPCWSTR
        char[] UncPath,   // LPWSTR optional, out
        IntByReference lpSize   // DWORD* in/out
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun DavGetUNCFromHTTPPath = DavGetUNCFromHTTPPath(
    Url : UInt16*,   # LPCWSTR
    UncPath : UInt16*,   # LPWSTR optional, out
    lpSize : 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 DavGetUNCFromHTTPPathNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef DavGetUNCFromHTTPPathDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final DavGetUNCFromHTTPPath = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<DavGetUNCFromHTTPPathNative, DavGetUNCFromHTTPPathDart>('DavGetUNCFromHTTPPath');
// Url : LPCWSTR -> Pointer<Utf16>
// UncPath : LPWSTR optional, out -> Pointer<Utf16>
// lpSize : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DavGetUNCFromHTTPPath(
  Url: PWideChar;   // LPCWSTR
  UncPath: PWideChar;   // LPWSTR optional, out
  lpSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'DavGetUNCFromHTTPPath';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DavGetUNCFromHTTPPath"
  c_DavGetUNCFromHTTPPath :: CWString -> CWString -> Ptr Word32 -> IO Word32
-- Url : LPCWSTR -> CWString
-- UncPath : LPWSTR optional, out -> CWString
-- lpSize : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let davgetuncfromhttppath =
  foreign "DavGetUNCFromHTTPPath"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* Url : LPCWSTR -> (ptr uint16_t) *)
(* UncPath : LPWSTR optional, out -> (ptr uint16_t) *)
(* lpSize : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("DavGetUNCFromHTTPPath" dav-get-uncfrom-httppath :convention :stdcall) :uint32
  (url (:string :encoding :utf-16le))   ; LPCWSTR
  (unc-path :pointer)   ; LPWSTR optional, out
  (lp-size :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DavGetUNCFromHTTPPath = Win32::API::More->new('NETAPI32',
    'DWORD DavGetUNCFromHTTPPath(LPCWSTR Url, LPWSTR UncPath, LPVOID lpSize)');
# my $ret = $DavGetUNCFromHTTPPath->Call($Url, $UncPath, $lpSize);
# Url : LPCWSTR -> LPCWSTR
# UncPath : LPWSTR optional, out -> LPWSTR
# lpSize : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。