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

NetConfigGetAll

関数
指定コンポーネントの全構成パラメータをまとめて取得する。
DLLNETAPI32.dll呼出規約winapi

シグネチャ

// NETAPI32.dll
#include <windows.h>

DWORD NetConfigGetAll(
    LPCWSTR server,
    LPCWSTR component,
    BYTE** bufptr
);

パラメーター

名前方向説明
serverLPCWSTRinTBD
componentLPCWSTRinTBD
bufptrBYTE**inoutTBD

戻り値の型: DWORD

公式ドキュメント

NetConfigGetAll 関数は廃止されています。16 ビット版の Windows との互換性のために含まれています。その他のアプリケーションではレジストリを使用してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// NETAPI32.dll
#include <windows.h>

DWORD NetConfigGetAll(
    LPCWSTR server,
    LPCWSTR component,
    BYTE** bufptr
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetConfigGetAll(
    [MarshalAs(UnmanagedType.LPWStr)] string server,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string component,   // LPCWSTR
    IntPtr bufptr   // BYTE** in/out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetConfigGetAll(
    <MarshalAs(UnmanagedType.LPWStr)> server As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> component As String,   ' LPCWSTR
    bufptr As IntPtr   ' BYTE** in/out
) As UInteger
End Function
' server : LPCWSTR
' component : LPCWSTR
' bufptr : BYTE** in/out
Declare PtrSafe Function NetConfigGetAll Lib "netapi32" ( _
    ByVal server As LongPtr, _
    ByVal component As LongPtr, _
    ByVal bufptr As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetConfigGetAll = ctypes.windll.netapi32.NetConfigGetAll
NetConfigGetAll.restype = wintypes.DWORD
NetConfigGetAll.argtypes = [
    wintypes.LPCWSTR,  # server : LPCWSTR
    wintypes.LPCWSTR,  # component : LPCWSTR
    ctypes.c_void_p,  # bufptr : BYTE** in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetConfigGetAll = Fiddle::Function.new(
  lib['NetConfigGetAll'],
  [
    Fiddle::TYPE_VOIDP,  # server : LPCWSTR
    Fiddle::TYPE_VOIDP,  # component : LPCWSTR
    Fiddle::TYPE_VOIDP,  # bufptr : BYTE** in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetConfigGetAll(
        server: *const u16,  // LPCWSTR
        component: *const u16,  // LPCWSTR
        bufptr: *mut *mut u8  // BYTE** in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetConfigGetAll([MarshalAs(UnmanagedType.LPWStr)] string server, [MarshalAs(UnmanagedType.LPWStr)] string component, IntPtr bufptr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetConfigGetAll' -Namespace Win32 -PassThru
# $api::NetConfigGetAll(server, component, bufptr)
#uselib "NETAPI32.dll"
#func global NetConfigGetAll "NetConfigGetAll" sptr, sptr, sptr
; NetConfigGetAll server, component, varptr(bufptr)   ; 戻り値は stat
; server : LPCWSTR -> "sptr"
; component : LPCWSTR -> "sptr"
; bufptr : BYTE** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "NETAPI32.dll"
#cfunc global NetConfigGetAll "NetConfigGetAll" wstr, wstr, var
; res = NetConfigGetAll(server, component, bufptr)
; server : LPCWSTR -> "wstr"
; component : LPCWSTR -> "wstr"
; bufptr : BYTE** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD NetConfigGetAll(LPCWSTR server, LPCWSTR component, BYTE** bufptr)
#uselib "NETAPI32.dll"
#cfunc global NetConfigGetAll "NetConfigGetAll" wstr, wstr, var
; res = NetConfigGetAll(server, component, bufptr)
; server : LPCWSTR -> "wstr"
; component : LPCWSTR -> "wstr"
; bufptr : BYTE** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetConfigGetAll = netapi32.NewProc("NetConfigGetAll")
)

// server (LPCWSTR), component (LPCWSTR), bufptr (BYTE** in/out)
r1, _, err := procNetConfigGetAll.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(server))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(component))),
	uintptr(bufptr),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetConfigGetAll(
  server: PWideChar;   // LPCWSTR
  component: PWideChar;   // LPCWSTR
  bufptr: Pointer   // BYTE** in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetConfigGetAll';
result := DllCall("NETAPI32\NetConfigGetAll"
    , "WStr", server   ; LPCWSTR
    , "WStr", component   ; LPCWSTR
    , "Ptr", bufptr   ; BYTE** in/out
    , "UInt")   ; return: DWORD
●NetConfigGetAll(server, component, bufptr) = DLL("NETAPI32.dll", "dword NetConfigGetAll(char*, char*, void*)")
# 呼び出し: NetConfigGetAll(server, component, bufptr)
# server : LPCWSTR -> "char*"
# component : LPCWSTR -> "char*"
# bufptr : BYTE** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn NetConfigGetAll(
    server: [*c]const u16, // LPCWSTR
    component: [*c]const u16, // LPCWSTR
    bufptr: [*c][*c]u8 // BYTE** in/out
) callconv(std.os.windows.WINAPI) u32;
proc NetConfigGetAll(
    server: WideCString,  # LPCWSTR
    component: WideCString,  # LPCWSTR
    bufptr: ptr uint8  # BYTE** in/out
): uint32 {.importc: "NetConfigGetAll", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetConfigGetAll(
    const(wchar)* server,   // LPCWSTR
    const(wchar)* component,   // LPCWSTR
    ubyte** bufptr   // BYTE** in/out
);
ccall((:NetConfigGetAll, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Ptr{UInt8}),
      server, component, bufptr)
# server : LPCWSTR -> Cwstring
# component : LPCWSTR -> Cwstring
# bufptr : BYTE** in/out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetConfigGetAll(
    const uint16_t* server,
    const uint16_t* component,
    uint8_t** bufptr);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetConfigGetAll(server, component, bufptr)
-- server : LPCWSTR
-- component : LPCWSTR
-- bufptr : BYTE** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetConfigGetAll = lib.func('__stdcall', 'NetConfigGetAll', 'uint32_t', ['str16', 'str16', 'uint8_t *']);
// NetConfigGetAll(server, component, bufptr)
// server : LPCWSTR -> 'str16'
// component : LPCWSTR -> 'str16'
// bufptr : BYTE** in/out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetConfigGetAll: { parameters: ["buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.NetConfigGetAll(server, component, bufptr)
// server : LPCWSTR -> "buffer"
// component : LPCWSTR -> "buffer"
// bufptr : BYTE** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetConfigGetAll(
    const uint16_t* server,
    const uint16_t* component,
    uint8_t** bufptr);
C, "NETAPI32.dll");
// $ffi->NetConfigGetAll(server, component, bufptr);
// server : LPCWSTR
// component : LPCWSTR
// bufptr : BYTE** 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 Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int NetConfigGetAll(
        WString server,   // LPCWSTR
        WString component,   // LPCWSTR
        Pointer bufptr   // BYTE** in/out
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetConfigGetAll = NetConfigGetAll(
    server : UInt16*,   # LPCWSTR
    component : UInt16*,   # LPCWSTR
    bufptr : UInt8**   # BYTE** 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 NetConfigGetAllNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint8>);
typedef NetConfigGetAllDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint8>);
final NetConfigGetAll = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetConfigGetAllNative, NetConfigGetAllDart>('NetConfigGetAll');
// server : LPCWSTR -> Pointer<Utf16>
// component : LPCWSTR -> Pointer<Utf16>
// bufptr : BYTE** in/out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetConfigGetAll(
  server: PWideChar;   // LPCWSTR
  component: PWideChar;   // LPCWSTR
  bufptr: Pointer   // BYTE** in/out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetConfigGetAll';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetConfigGetAll"
  c_NetConfigGetAll :: CWString -> CWString -> Ptr Word8 -> IO Word32
-- server : LPCWSTR -> CWString
-- component : LPCWSTR -> CWString
-- bufptr : BYTE** in/out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netconfiggetall =
  foreign "NetConfigGetAll"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint8_t) @-> returning uint32_t)
(* server : LPCWSTR -> (ptr uint16_t) *)
(* component : LPCWSTR -> (ptr uint16_t) *)
(* bufptr : BYTE** in/out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetConfigGetAll" net-config-get-all :convention :stdcall) :uint32
  (server (:string :encoding :utf-16le))   ; LPCWSTR
  (component (:string :encoding :utf-16le))   ; LPCWSTR
  (bufptr :pointer))   ; BYTE** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetConfigGetAll = Win32::API::More->new('NETAPI32',
    'DWORD NetConfigGetAll(LPCWSTR server, LPCWSTR component, LPVOID bufptr)');
# my $ret = $NetConfigGetAll->Call($server, $component, $bufptr);
# server : LPCWSTR -> LPCWSTR
# component : LPCWSTR -> LPCWSTR
# bufptr : BYTE** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。