ホーム › NetworkManagement.WNet › WNetGetResourceParentA
WNetGetResourceParentA
関数ネットワークリソースの親リソース情報を取得する(ANSI版)。
シグネチャ
// MPR.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR WNetGetResourceParentA(
NETRESOURCEA* lpNetResource,
void* lpBuffer,
DWORD* lpcbBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpNetResource | NETRESOURCEA* | in | 親を問い合わせる対象のNETRESOURCEA構造体へのポインタ。 |
| lpBuffer | void* | out | 親リソース情報(NETRESOURCEA)を受け取るバッファ。 |
| lpcbBuffer | DWORD* | inout | lpBufferのバイト数を入出力で渡し、不足時は必要量を受け取る。 |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// MPR.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR WNetGetResourceParentA(
NETRESOURCEA* lpNetResource,
void* lpBuffer,
DWORD* lpcbBuffer
);[DllImport("MPR.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint WNetGetResourceParentA(
IntPtr lpNetResource, // NETRESOURCEA*
IntPtr lpBuffer, // void* out
ref uint lpcbBuffer // DWORD* in/out
);<DllImport("MPR.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function WNetGetResourceParentA(
lpNetResource As IntPtr, ' NETRESOURCEA*
lpBuffer As IntPtr, ' void* out
ByRef lpcbBuffer As UInteger ' DWORD* in/out
) As UInteger
End Function' lpNetResource : NETRESOURCEA*
' lpBuffer : void* out
' lpcbBuffer : DWORD* in/out
Declare PtrSafe Function WNetGetResourceParentA Lib "mpr" ( _
ByVal lpNetResource As LongPtr, _
ByVal lpBuffer As LongPtr, _
ByRef lpcbBuffer As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WNetGetResourceParentA = ctypes.windll.mpr.WNetGetResourceParentA
WNetGetResourceParentA.restype = wintypes.DWORD
WNetGetResourceParentA.argtypes = [
ctypes.c_void_p, # lpNetResource : NETRESOURCEA*
ctypes.POINTER(None), # lpBuffer : void* out
ctypes.POINTER(wintypes.DWORD), # lpcbBuffer : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MPR.dll')
WNetGetResourceParentA = Fiddle::Function.new(
lib['WNetGetResourceParentA'],
[
Fiddle::TYPE_VOIDP, # lpNetResource : NETRESOURCEA*
Fiddle::TYPE_VOIDP, # lpBuffer : void* out
Fiddle::TYPE_VOIDP, # lpcbBuffer : DWORD* in/out
],
-Fiddle::TYPE_INT)#[link(name = "mpr")]
extern "system" {
fn WNetGetResourceParentA(
lpNetResource: *mut NETRESOURCEA, // NETRESOURCEA*
lpBuffer: *mut (), // void* out
lpcbBuffer: *mut u32 // DWORD* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MPR.dll", CharSet = CharSet.Ansi)]
public static extern uint WNetGetResourceParentA(IntPtr lpNetResource, IntPtr lpBuffer, ref uint lpcbBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPR_WNetGetResourceParentA' -Namespace Win32 -PassThru
# $api::WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer)#uselib "MPR.dll"
#func global WNetGetResourceParentA "WNetGetResourceParentA" sptr, sptr, sptr
; WNetGetResourceParentA varptr(lpNetResource), lpBuffer, varptr(lpcbBuffer) ; 戻り値は stat
; lpNetResource : NETRESOURCEA* -> "sptr"
; lpBuffer : void* out -> "sptr"
; lpcbBuffer : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MPR.dll" #cfunc global WNetGetResourceParentA "WNetGetResourceParentA" var, sptr, var ; res = WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer) ; lpNetResource : NETRESOURCEA* -> "var" ; lpBuffer : void* out -> "sptr" ; lpcbBuffer : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MPR.dll" #cfunc global WNetGetResourceParentA "WNetGetResourceParentA" sptr, sptr, sptr ; res = WNetGetResourceParentA(varptr(lpNetResource), lpBuffer, varptr(lpcbBuffer)) ; lpNetResource : NETRESOURCEA* -> "sptr" ; lpBuffer : void* out -> "sptr" ; lpcbBuffer : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR WNetGetResourceParentA(NETRESOURCEA* lpNetResource, void* lpBuffer, DWORD* lpcbBuffer) #uselib "MPR.dll" #cfunc global WNetGetResourceParentA "WNetGetResourceParentA" var, intptr, var ; res = WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer) ; lpNetResource : NETRESOURCEA* -> "var" ; lpBuffer : void* out -> "intptr" ; lpcbBuffer : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR WNetGetResourceParentA(NETRESOURCEA* lpNetResource, void* lpBuffer, DWORD* lpcbBuffer) #uselib "MPR.dll" #cfunc global WNetGetResourceParentA "WNetGetResourceParentA" intptr, intptr, intptr ; res = WNetGetResourceParentA(varptr(lpNetResource), lpBuffer, varptr(lpcbBuffer)) ; lpNetResource : NETRESOURCEA* -> "intptr" ; lpBuffer : void* out -> "intptr" ; lpcbBuffer : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mpr = windows.NewLazySystemDLL("MPR.dll")
procWNetGetResourceParentA = mpr.NewProc("WNetGetResourceParentA")
)
// lpNetResource (NETRESOURCEA*), lpBuffer (void* out), lpcbBuffer (DWORD* in/out)
r1, _, err := procWNetGetResourceParentA.Call(
uintptr(lpNetResource),
uintptr(lpBuffer),
uintptr(lpcbBuffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction WNetGetResourceParentA(
lpNetResource: Pointer; // NETRESOURCEA*
lpBuffer: Pointer; // void* out
lpcbBuffer: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'MPR.dll' name 'WNetGetResourceParentA';result := DllCall("MPR\WNetGetResourceParentA"
, "Ptr", lpNetResource ; NETRESOURCEA*
, "Ptr", lpBuffer ; void* out
, "Ptr", lpcbBuffer ; DWORD* in/out
, "UInt") ; return: WIN32_ERROR●WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer) = DLL("MPR.dll", "dword WNetGetResourceParentA(void*, void*, void*)")
# 呼び出し: WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer)
# lpNetResource : NETRESOURCEA* -> "void*"
# lpBuffer : void* out -> "void*"
# lpcbBuffer : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mpr" fn WNetGetResourceParentA(
lpNetResource: [*c]NETRESOURCEA, // NETRESOURCEA*
lpBuffer: ?*anyopaque, // void* out
lpcbBuffer: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;proc WNetGetResourceParentA(
lpNetResource: ptr NETRESOURCEA, # NETRESOURCEA*
lpBuffer: pointer, # void* out
lpcbBuffer: ptr uint32 # DWORD* in/out
): uint32 {.importc: "WNetGetResourceParentA", stdcall, dynlib: "MPR.dll".}pragma(lib, "mpr");
extern(Windows)
uint WNetGetResourceParentA(
NETRESOURCEA* lpNetResource, // NETRESOURCEA*
void* lpBuffer, // void* out
uint* lpcbBuffer // DWORD* in/out
);ccall((:WNetGetResourceParentA, "MPR.dll"), stdcall, UInt32,
(Ptr{NETRESOURCEA}, Ptr{Cvoid}, Ptr{UInt32}),
lpNetResource, lpBuffer, lpcbBuffer)
# lpNetResource : NETRESOURCEA* -> Ptr{NETRESOURCEA}
# lpBuffer : void* out -> Ptr{Cvoid}
# lpcbBuffer : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t WNetGetResourceParentA(
void* lpNetResource,
void* lpBuffer,
uint32_t* lpcbBuffer);
]]
local mpr = ffi.load("mpr")
-- mpr.WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer)
-- lpNetResource : NETRESOURCEA*
-- lpBuffer : void* out
-- lpcbBuffer : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MPR.dll');
const WNetGetResourceParentA = lib.func('__stdcall', 'WNetGetResourceParentA', 'uint32_t', ['void *', 'void *', 'uint32_t *']);
// WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer)
// lpNetResource : NETRESOURCEA* -> 'void *'
// lpBuffer : void* out -> 'void *'
// lpcbBuffer : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MPR.dll", {
WNetGetResourceParentA: { parameters: ["pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer)
// lpNetResource : NETRESOURCEA* -> "pointer"
// lpBuffer : void* out -> "pointer"
// lpcbBuffer : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t WNetGetResourceParentA(
void* lpNetResource,
void* lpBuffer,
uint32_t* lpcbBuffer);
C, "MPR.dll");
// $ffi->WNetGetResourceParentA(lpNetResource, lpBuffer, lpcbBuffer);
// lpNetResource : NETRESOURCEA*
// lpBuffer : void* out
// lpcbBuffer : 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 Mpr extends StdCallLibrary {
Mpr INSTANCE = Native.load("mpr", Mpr.class, W32APIOptions.ASCII_OPTIONS);
int WNetGetResourceParentA(
Pointer lpNetResource, // NETRESOURCEA*
Pointer lpBuffer, // void* out
IntByReference lpcbBuffer // DWORD* in/out
);
}@[Link("mpr")]
lib LibMPR
fun WNetGetResourceParentA = WNetGetResourceParentA(
lpNetResource : NETRESOURCEA*, # NETRESOURCEA*
lpBuffer : Void*, # void* out
lpcbBuffer : 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 WNetGetResourceParentANative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef WNetGetResourceParentADart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final WNetGetResourceParentA = DynamicLibrary.open('MPR.dll')
.lookupFunction<WNetGetResourceParentANative, WNetGetResourceParentADart>('WNetGetResourceParentA');
// lpNetResource : NETRESOURCEA* -> Pointer<Void>
// lpBuffer : void* out -> Pointer<Void>
// lpcbBuffer : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WNetGetResourceParentA(
lpNetResource: Pointer; // NETRESOURCEA*
lpBuffer: Pointer; // void* out
lpcbBuffer: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'MPR.dll' name 'WNetGetResourceParentA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WNetGetResourceParentA"
c_WNetGetResourceParentA :: Ptr () -> Ptr () -> Ptr Word32 -> IO Word32
-- lpNetResource : NETRESOURCEA* -> Ptr ()
-- lpBuffer : void* out -> Ptr ()
-- lpcbBuffer : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wnetgetresourceparenta =
foreign "WNetGetResourceParentA"
((ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> returning uint32_t)
(* lpNetResource : NETRESOURCEA* -> (ptr void) *)
(* lpBuffer : void* out -> (ptr void) *)
(* lpcbBuffer : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mpr (t "MPR.dll"))
(cffi:use-foreign-library mpr)
(cffi:defcfun ("WNetGetResourceParentA" wnet-get-resource-parent-a :convention :stdcall) :uint32
(lp-net-resource :pointer) ; NETRESOURCEA*
(lp-buffer :pointer) ; void* out
(lpcb-buffer :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WNetGetResourceParentA = Win32::API::More->new('MPR',
'DWORD WNetGetResourceParentA(LPVOID lpNetResource, LPVOID lpBuffer, LPVOID lpcbBuffer)');
# my $ret = $WNetGetResourceParentA->Call($lpNetResource, $lpBuffer, $lpcbBuffer);
# lpNetResource : NETRESOURCEA* -> LPVOID
# lpBuffer : void* out -> LPVOID
# lpcbBuffer : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f WNetGetResourceParentW (Unicode版) — ネットワークリソースの親リソース情報を取得する(Unicode版)。