SHValidateUNC
関数UNCパスの妥当性を検証し必要なら接続する。
シグネチャ
// SHELL32.dll
#include <windows.h>
BOOL SHValidateUNC(
HWND hwndOwner, // optional
LPWSTR pszFile,
DWORD fConnect
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwndOwner | HWND | inoptional |
| pszFile | LPWSTR | inout |
| fConnect | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
BOOL SHValidateUNC(
HWND hwndOwner, // optional
LPWSTR pszFile,
DWORD fConnect
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern bool SHValidateUNC(
IntPtr hwndOwner, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszFile, // LPWSTR in/out
uint fConnect // DWORD
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHValidateUNC(
hwndOwner As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszFile As System.Text.StringBuilder, ' LPWSTR in/out
fConnect As UInteger ' DWORD
) As Boolean
End Function' hwndOwner : HWND optional
' pszFile : LPWSTR in/out
' fConnect : DWORD
Declare PtrSafe Function SHValidateUNC Lib "shell32" ( _
ByVal hwndOwner As LongPtr, _
ByVal pszFile As LongPtr, _
ByVal fConnect As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHValidateUNC = ctypes.windll.shell32.SHValidateUNC
SHValidateUNC.restype = wintypes.BOOL
SHValidateUNC.argtypes = [
wintypes.HANDLE, # hwndOwner : HWND optional
wintypes.LPWSTR, # pszFile : LPWSTR in/out
wintypes.DWORD, # fConnect : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHValidateUNC = Fiddle::Function.new(
lib['SHValidateUNC'],
[
Fiddle::TYPE_VOIDP, # hwndOwner : HWND optional
Fiddle::TYPE_VOIDP, # pszFile : LPWSTR in/out
-Fiddle::TYPE_INT, # fConnect : DWORD
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHValidateUNC(
hwndOwner: *mut core::ffi::c_void, // HWND optional
pszFile: *mut u16, // LPWSTR in/out
fConnect: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll")]
public static extern bool SHValidateUNC(IntPtr hwndOwner, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszFile, uint fConnect);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHValidateUNC' -Namespace Win32 -PassThru
# $api::SHValidateUNC(hwndOwner, pszFile, fConnect)#uselib "SHELL32.dll"
#func global SHValidateUNC "SHValidateUNC" sptr, sptr, sptr
; SHValidateUNC hwndOwner, varptr(pszFile), fConnect ; 戻り値は stat
; hwndOwner : HWND optional -> "sptr"
; pszFile : LPWSTR in/out -> "sptr"
; fConnect : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHValidateUNC "SHValidateUNC" sptr, var, int ; res = SHValidateUNC(hwndOwner, pszFile, fConnect) ; hwndOwner : HWND optional -> "sptr" ; pszFile : LPWSTR in/out -> "var" ; fConnect : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHValidateUNC "SHValidateUNC" sptr, sptr, int ; res = SHValidateUNC(hwndOwner, varptr(pszFile), fConnect) ; hwndOwner : HWND optional -> "sptr" ; pszFile : LPWSTR in/out -> "sptr" ; fConnect : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SHValidateUNC(HWND hwndOwner, LPWSTR pszFile, DWORD fConnect) #uselib "SHELL32.dll" #cfunc global SHValidateUNC "SHValidateUNC" intptr, var, int ; res = SHValidateUNC(hwndOwner, pszFile, fConnect) ; hwndOwner : HWND optional -> "intptr" ; pszFile : LPWSTR in/out -> "var" ; fConnect : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SHValidateUNC(HWND hwndOwner, LPWSTR pszFile, DWORD fConnect) #uselib "SHELL32.dll" #cfunc global SHValidateUNC "SHValidateUNC" intptr, intptr, int ; res = SHValidateUNC(hwndOwner, varptr(pszFile), fConnect) ; hwndOwner : HWND optional -> "intptr" ; pszFile : LPWSTR in/out -> "intptr" ; fConnect : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHValidateUNC = shell32.NewProc("SHValidateUNC")
)
// hwndOwner (HWND optional), pszFile (LPWSTR in/out), fConnect (DWORD)
r1, _, err := procSHValidateUNC.Call(
uintptr(hwndOwner),
uintptr(pszFile),
uintptr(fConnect),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SHValidateUNC(
hwndOwner: THandle; // HWND optional
pszFile: PWideChar; // LPWSTR in/out
fConnect: DWORD // DWORD
): BOOL; stdcall;
external 'SHELL32.dll' name 'SHValidateUNC';result := DllCall("SHELL32\SHValidateUNC"
, "Ptr", hwndOwner ; HWND optional
, "Ptr", pszFile ; LPWSTR in/out
, "UInt", fConnect ; DWORD
, "Int") ; return: BOOL●SHValidateUNC(hwndOwner, pszFile, fConnect) = DLL("SHELL32.dll", "bool SHValidateUNC(void*, char*, dword)")
# 呼び出し: SHValidateUNC(hwndOwner, pszFile, fConnect)
# hwndOwner : HWND optional -> "void*"
# pszFile : LPWSTR in/out -> "char*"
# fConnect : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。