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

WNetCancelConnectionW

関数
ネットワークリソースへの接続を切断する(Unicode版)。
DLLMPR.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetCancelConnectionW(
    LPCWSTR lpName,
    BOOL fForce
);

パラメーター

名前方向
lpNameLPCWSTRin
fForceBOOLin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// MPR.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR WNetCancelConnectionW(
    LPCWSTR lpName,
    BOOL fForce
);
[DllImport("MPR.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint WNetCancelConnectionW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpName,   // LPCWSTR
    bool fForce   // BOOL
);
<DllImport("MPR.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function WNetCancelConnectionW(
    <MarshalAs(UnmanagedType.LPWStr)> lpName As String,   ' LPCWSTR
    fForce As Boolean   ' BOOL
) As UInteger
End Function
' lpName : LPCWSTR
' fForce : BOOL
Declare PtrSafe Function WNetCancelConnectionW Lib "mpr" ( _
    ByVal lpName As LongPtr, _
    ByVal fForce 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

WNetCancelConnectionW = ctypes.windll.mpr.WNetCancelConnectionW
WNetCancelConnectionW.restype = wintypes.DWORD
WNetCancelConnectionW.argtypes = [
    wintypes.LPCWSTR,  # lpName : LPCWSTR
    wintypes.BOOL,  # fForce : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPR.dll')
WNetCancelConnectionW = Fiddle::Function.new(
  lib['WNetCancelConnectionW'],
  [
    Fiddle::TYPE_VOIDP,  # lpName : LPCWSTR
    Fiddle::TYPE_INT,  # fForce : BOOL
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "mpr")]
extern "system" {
    fn WNetCancelConnectionW(
        lpName: *const u16,  // LPCWSTR
        fForce: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MPR.dll", CharSet = CharSet.Unicode)]
public static extern uint WNetCancelConnectionW([MarshalAs(UnmanagedType.LPWStr)] string lpName, bool fForce);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetCancelConnectionW' -Namespace Win32 -PassThru
# $api::WNetCancelConnectionW(lpName, fForce)
#uselib "MPR.dll"
#func global WNetCancelConnectionW "WNetCancelConnectionW" wptr, wptr
; WNetCancelConnectionW lpName, fForce   ; 戻り値は stat
; lpName : LPCWSTR -> "wptr"
; fForce : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MPR.dll"
#cfunc global WNetCancelConnectionW "WNetCancelConnectionW" wstr, int
; res = WNetCancelConnectionW(lpName, fForce)
; lpName : LPCWSTR -> "wstr"
; fForce : BOOL -> "int"
; WIN32_ERROR WNetCancelConnectionW(LPCWSTR lpName, BOOL fForce)
#uselib "MPR.dll"
#cfunc global WNetCancelConnectionW "WNetCancelConnectionW" wstr, int
; res = WNetCancelConnectionW(lpName, fForce)
; lpName : LPCWSTR -> "wstr"
; fForce : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetCancelConnectionW = mpr.NewProc("WNetCancelConnectionW")
)

// lpName (LPCWSTR), fForce (BOOL)
r1, _, err := procWNetCancelConnectionW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
	uintptr(fForce),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetCancelConnectionW(
  lpName: PWideChar;   // LPCWSTR
  fForce: BOOL   // BOOL
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetCancelConnectionW';
result := DllCall("MPR\WNetCancelConnectionW"
    , "WStr", lpName   ; LPCWSTR
    , "Int", fForce   ; BOOL
    , "UInt")   ; return: WIN32_ERROR
●WNetCancelConnectionW(lpName, fForce) = DLL("MPR.dll", "dword WNetCancelConnectionW(char*, bool)")
# 呼び出し: WNetCancelConnectionW(lpName, fForce)
# lpName : LPCWSTR -> "char*"
# fForce : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。