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