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

NetApiBufferReallocate

関数
ネットワークAPI用バッファのサイズを再割り当てして変更する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD NetApiBufferReallocate(
    void* OldBuffer,   // optional
    DWORD NewByteCount,
    void** NewBuffer
);

パラメーター

名前方向
OldBuffervoid*inoptional
NewByteCountDWORDin
NewBuffervoid**out

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetApiBufferReallocate(
    void* OldBuffer,   // optional
    DWORD NewByteCount,
    void** NewBuffer
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetApiBufferReallocate(
    IntPtr OldBuffer,   // void* optional
    uint NewByteCount,   // DWORD
    IntPtr NewBuffer   // void** out
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetApiBufferReallocate(
    OldBuffer As IntPtr,   ' void* optional
    NewByteCount As UInteger,   ' DWORD
    NewBuffer As IntPtr   ' void** out
) As UInteger
End Function
' OldBuffer : void* optional
' NewByteCount : DWORD
' NewBuffer : void** out
Declare PtrSafe Function NetApiBufferReallocate Lib "netapi32" ( _
    ByVal OldBuffer As LongPtr, _
    ByVal NewByteCount As Long, _
    ByVal NewBuffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetApiBufferReallocate = ctypes.windll.netapi32.NetApiBufferReallocate
NetApiBufferReallocate.restype = wintypes.DWORD
NetApiBufferReallocate.argtypes = [
    ctypes.POINTER(None),  # OldBuffer : void* optional
    wintypes.DWORD,  # NewByteCount : DWORD
    ctypes.c_void_p,  # NewBuffer : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetApiBufferReallocate = Fiddle::Function.new(
  lib['NetApiBufferReallocate'],
  [
    Fiddle::TYPE_VOIDP,  # OldBuffer : void* optional
    -Fiddle::TYPE_INT,  # NewByteCount : DWORD
    Fiddle::TYPE_VOIDP,  # NewBuffer : void** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetApiBufferReallocate(
        OldBuffer: *mut (),  // void* optional
        NewByteCount: u32,  // DWORD
        NewBuffer: *mut *mut ()  // void** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetApiBufferReallocate(IntPtr OldBuffer, uint NewByteCount, IntPtr NewBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetApiBufferReallocate' -Namespace Win32 -PassThru
# $api::NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
#uselib "NETAPI32.dll"
#func global NetApiBufferReallocate "NetApiBufferReallocate" sptr, sptr, sptr
; NetApiBufferReallocate OldBuffer, NewByteCount, NewBuffer   ; 戻り値は stat
; OldBuffer : void* optional -> "sptr"
; NewByteCount : DWORD -> "sptr"
; NewBuffer : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetApiBufferReallocate "NetApiBufferReallocate" sptr, int, sptr
; res = NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
; OldBuffer : void* optional -> "sptr"
; NewByteCount : DWORD -> "int"
; NewBuffer : void** out -> "sptr"
; DWORD NetApiBufferReallocate(void* OldBuffer, DWORD NewByteCount, void** NewBuffer)
#uselib "NETAPI32.dll"
#cfunc global NetApiBufferReallocate "NetApiBufferReallocate" intptr, int, intptr
; res = NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
; OldBuffer : void* optional -> "intptr"
; NewByteCount : DWORD -> "int"
; NewBuffer : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetApiBufferReallocate = netapi32.NewProc("NetApiBufferReallocate")
)

// OldBuffer (void* optional), NewByteCount (DWORD), NewBuffer (void** out)
r1, _, err := procNetApiBufferReallocate.Call(
	uintptr(OldBuffer),
	uintptr(NewByteCount),
	uintptr(NewBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetApiBufferReallocate(
  OldBuffer: Pointer;   // void* optional
  NewByteCount: DWORD;   // DWORD
  NewBuffer: Pointer   // void** out
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetApiBufferReallocate';
result := DllCall("NETAPI32\NetApiBufferReallocate"
    , "Ptr", OldBuffer   ; void* optional
    , "UInt", NewByteCount   ; DWORD
    , "Ptr", NewBuffer   ; void** out
    , "UInt")   ; return: DWORD
●NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer) = DLL("NETAPI32.dll", "dword NetApiBufferReallocate(void*, dword, void*)")
# 呼び出し: NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
# OldBuffer : void* optional -> "void*"
# NewByteCount : DWORD -> "dword"
# NewBuffer : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。