ホーム › NetworkManagement.WNet › NPCancelConnection
NPCancelConnection
関数ネットワークプロバイダー経由の接続を切断する。
シグネチャ
// davclnt.dll
#include <windows.h>
DWORD NPCancelConnection(
LPWSTR lpName,
BOOL fForce
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpName | LPWSTR | in | 切断対象のローカルデバイス名またはリモート名のワイド文字列。 |
| fForce | BOOL | in | オープン中のファイルがあっても強制切断するかを示すブール値。 |
戻り値の型: DWORD
各言語での呼び出し定義
// davclnt.dll
#include <windows.h>
DWORD NPCancelConnection(
LPWSTR lpName,
BOOL fForce
);[DllImport("davclnt.dll", ExactSpelling = true)]
static extern uint NPCancelConnection(
[MarshalAs(UnmanagedType.LPWStr)] string lpName, // LPWSTR
bool fForce // BOOL
);<DllImport("davclnt.dll", ExactSpelling:=True)>
Public Shared Function NPCancelConnection(
<MarshalAs(UnmanagedType.LPWStr)> lpName As String, ' LPWSTR
fForce As Boolean ' BOOL
) As UInteger
End Function' lpName : LPWSTR
' fForce : BOOL
Declare PtrSafe Function NPCancelConnection Lib "davclnt" ( _
ByVal lpName As LongPtr, _
ByVal fForce As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NPCancelConnection = ctypes.windll.davclnt.NPCancelConnection
NPCancelConnection.restype = wintypes.DWORD
NPCancelConnection.argtypes = [
wintypes.LPCWSTR, # lpName : LPWSTR
wintypes.BOOL, # fForce : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('davclnt.dll')
NPCancelConnection = Fiddle::Function.new(
lib['NPCancelConnection'],
[
Fiddle::TYPE_VOIDP, # lpName : LPWSTR
Fiddle::TYPE_INT, # fForce : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "davclnt")]
extern "system" {
fn NPCancelConnection(
lpName: *mut u16, // LPWSTR
fForce: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("davclnt.dll")]
public static extern uint NPCancelConnection([MarshalAs(UnmanagedType.LPWStr)] string lpName, bool fForce);
"@
$api = Add-Type -MemberDefinition $sig -Name 'davclnt_NPCancelConnection' -Namespace Win32 -PassThru
# $api::NPCancelConnection(lpName, fForce)#uselib "davclnt.dll"
#func global NPCancelConnection "NPCancelConnection" sptr, sptr
; NPCancelConnection lpName, fForce ; 戻り値は stat
; lpName : LPWSTR -> "sptr"
; fForce : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "davclnt.dll"
#cfunc global NPCancelConnection "NPCancelConnection" wstr, int
; res = NPCancelConnection(lpName, fForce)
; lpName : LPWSTR -> "wstr"
; fForce : BOOL -> "int"; DWORD NPCancelConnection(LPWSTR lpName, BOOL fForce)
#uselib "davclnt.dll"
#cfunc global NPCancelConnection "NPCancelConnection" wstr, int
; res = NPCancelConnection(lpName, fForce)
; lpName : LPWSTR -> "wstr"
; fForce : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
davclnt = windows.NewLazySystemDLL("davclnt.dll")
procNPCancelConnection = davclnt.NewProc("NPCancelConnection")
)
// lpName (LPWSTR), fForce (BOOL)
r1, _, err := procNPCancelConnection.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
uintptr(fForce),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction NPCancelConnection(
lpName: PWideChar; // LPWSTR
fForce: BOOL // BOOL
): DWORD; stdcall;
external 'davclnt.dll' name 'NPCancelConnection';result := DllCall("davclnt\NPCancelConnection"
, "WStr", lpName ; LPWSTR
, "Int", fForce ; BOOL
, "UInt") ; return: DWORD●NPCancelConnection(lpName, fForce) = DLL("davclnt.dll", "dword NPCancelConnection(char*, bool)")
# 呼び出し: NPCancelConnection(lpName, fForce)
# lpName : LPWSTR -> "char*"
# fForce : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "davclnt" fn NPCancelConnection(
lpName: [*c]const u16, // LPWSTR
fForce: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;proc NPCancelConnection(
lpName: WideCString, # LPWSTR
fForce: int32 # BOOL
): uint32 {.importc: "NPCancelConnection", stdcall, dynlib: "davclnt.dll".}pragma(lib, "davclnt");
extern(Windows)
uint NPCancelConnection(
const(wchar)* lpName, // LPWSTR
int fForce // BOOL
);ccall((:NPCancelConnection, "davclnt.dll"), stdcall, UInt32,
(Cwstring, Int32),
lpName, fForce)
# lpName : LPWSTR -> Cwstring
# fForce : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NPCancelConnection(
const uint16_t* lpName,
int32_t fForce);
]]
local davclnt = ffi.load("davclnt")
-- davclnt.NPCancelConnection(lpName, fForce)
-- lpName : LPWSTR
-- fForce : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('davclnt.dll');
const NPCancelConnection = lib.func('__stdcall', 'NPCancelConnection', 'uint32_t', ['str16', 'int32_t']);
// NPCancelConnection(lpName, fForce)
// lpName : LPWSTR -> 'str16'
// fForce : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("davclnt.dll", {
NPCancelConnection: { parameters: ["buffer", "i32"], result: "u32" },
});
// lib.symbols.NPCancelConnection(lpName, fForce)
// lpName : LPWSTR -> "buffer"
// fForce : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NPCancelConnection(
const uint16_t* lpName,
int32_t fForce);
C, "davclnt.dll");
// $ffi->NPCancelConnection(lpName, fForce);
// lpName : LPWSTR
// fForce : BOOL
// 構造体/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 Davclnt extends StdCallLibrary {
Davclnt INSTANCE = Native.load("davclnt", Davclnt.class);
int NPCancelConnection(
WString lpName, // LPWSTR
boolean fForce // BOOL
);
}@[Link("davclnt")]
lib Libdavclnt
fun NPCancelConnection = NPCancelConnection(
lpName : UInt16*, # LPWSTR
fForce : Int32 # BOOL
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NPCancelConnectionNative = Uint32 Function(Pointer<Utf16>, Int32);
typedef NPCancelConnectionDart = int Function(Pointer<Utf16>, int);
final NPCancelConnection = DynamicLibrary.open('davclnt.dll')
.lookupFunction<NPCancelConnectionNative, NPCancelConnectionDart>('NPCancelConnection');
// lpName : LPWSTR -> Pointer<Utf16>
// fForce : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NPCancelConnection(
lpName: PWideChar; // LPWSTR
fForce: BOOL // BOOL
): DWORD; stdcall;
external 'davclnt.dll' name 'NPCancelConnection';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NPCancelConnection"
c_NPCancelConnection :: CWString -> CInt -> IO Word32
-- lpName : LPWSTR -> CWString
-- fForce : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let npcancelconnection =
foreign "NPCancelConnection"
((ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* lpName : LPWSTR -> (ptr uint16_t) *)
(* fForce : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library davclnt (t "davclnt.dll"))
(cffi:use-foreign-library davclnt)
(cffi:defcfun ("NPCancelConnection" npcancel-connection :convention :stdcall) :uint32
(lp-name (:string :encoding :utf-16le)) ; LPWSTR
(f-force :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NPCancelConnection = Win32::API::More->new('davclnt',
'DWORD NPCancelConnection(LPCWSTR lpName, BOOL fForce)');
# my $ret = $NPCancelConnection->Call($lpName, $fForce);
# lpName : LPWSTR -> LPCWSTR
# fForce : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f NPCancelConnection2 — フラグを指定してプロバイダー経由の接続を切断する。