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

WNetCancelConnectionA

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

シグネチャ

// MPR.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR WNetCancelConnectionA(
    LPCSTR lpName,
    BOOL fForce
);

パラメーター

名前方向
lpNameLPCSTRin
fForceBOOLin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// MPR.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR WNetCancelConnectionA(
    LPCSTR lpName,
    BOOL fForce
);
[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetCancelConnectionA(
    [MarshalAs(UnmanagedType.LPStr)] string lpName,   // LPCSTR
    bool fForce   // BOOL
);
<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetCancelConnectionA(
    <MarshalAs(UnmanagedType.LPStr)> lpName As String,   ' LPCSTR
    fForce As Boolean   ' BOOL
) As UInteger
End Function
' lpName : LPCSTR
' fForce : BOOL
Declare PtrSafe Function WNetCancelConnectionA Lib "mpr" ( _
    ByVal lpName As String, _
    ByVal fForce As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	mpr = windows.NewLazySystemDLL("MPR.dll")
	procWNetCancelConnectionA = mpr.NewProc("WNetCancelConnectionA")
)

// lpName (LPCSTR), fForce (BOOL)
r1, _, err := procWNetCancelConnectionA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpName))),
	uintptr(fForce),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function WNetCancelConnectionA(
  lpName: PAnsiChar;   // LPCSTR
  fForce: BOOL   // BOOL
): DWORD; stdcall;
  external 'MPR.dll' name 'WNetCancelConnectionA';
result := DllCall("MPR\WNetCancelConnectionA"
    , "AStr", lpName   ; LPCSTR
    , "Int", fForce   ; BOOL
    , "UInt")   ; return: WIN32_ERROR
●WNetCancelConnectionA(lpName, fForce) = DLL("MPR.dll", "dword WNetCancelConnectionA(char*, bool)")
# 呼び出し: WNetCancelConnectionA(lpName, fForce)
# lpName : LPCSTR -> "char*"
# fForce : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。