ホーム › NetworkManagement.NetManagement › NetApiBufferReallocate
NetApiBufferReallocate
関数ネットワークAPI用バッファのサイズを再割り当てして変更する。
シグネチャ
// NETAPI32.dll
#include <windows.h>
DWORD NetApiBufferReallocate(
void* OldBuffer, // optional
DWORD NewByteCount,
void** NewBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| OldBuffer | void* | inoptional | NetApiBufferAllocate 関数の呼び出しによって返されたバッファへのポインターです。 |
| NewByteCount | DWORD | in | バッファの新しいサイズをバイト単位で指定します。 |
| NewBuffer | void** | out | 再割り当てされたバッファへのポインターを受け取ります。 |
戻り値の型: DWORD
公式ドキュメント
NetApiBufferReallocate 関数は、以前の NetApiBufferAllocate 関数の呼び出しによって割り当てられたバッファのサイズを変更します。
戻り値
関数が成功した場合、戻り値は NERR_Success です。
関数が失敗した場合、戻り値はシステム エラー コードです。エラー コードの一覧については、System Error Codes を参照してください。
解説(Remarks)
ApiBuffer 関数を正常に実行するために特別なグループ メンバーシップは必要ありません。
ネットワーク管理の ApiBuffer functions の使用方法を示すコード サンプルについては、NetApiBufferAllocate を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // DWORDfunction 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)。const std = @import("std");
extern "netapi32" fn NetApiBufferReallocate(
OldBuffer: ?*anyopaque, // void* optional
NewByteCount: u32, // DWORD
NewBuffer: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;proc NetApiBufferReallocate(
OldBuffer: pointer, # void* optional
NewByteCount: uint32, # DWORD
NewBuffer: pointer # void** out
): uint32 {.importc: "NetApiBufferReallocate", stdcall, dynlib: "NETAPI32.dll".}pragma(lib, "netapi32");
extern(Windows)
uint NetApiBufferReallocate(
void* OldBuffer, // void* optional
uint NewByteCount, // DWORD
void** NewBuffer // void** out
);ccall((:NetApiBufferReallocate, "NETAPI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}),
OldBuffer, NewByteCount, NewBuffer)
# OldBuffer : void* optional -> Ptr{Cvoid}
# NewByteCount : DWORD -> UInt32
# NewBuffer : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NetApiBufferReallocate(
void* OldBuffer,
uint32_t NewByteCount,
void** NewBuffer);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
-- OldBuffer : void* optional
-- NewByteCount : DWORD
-- NewBuffer : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetApiBufferReallocate = lib.func('__stdcall', 'NetApiBufferReallocate', 'uint32_t', ['void *', 'uint32_t', 'void *']);
// NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
// OldBuffer : void* optional -> 'void *'
// NewByteCount : DWORD -> 'uint32_t'
// NewBuffer : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NETAPI32.dll", {
NetApiBufferReallocate: { parameters: ["pointer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer)
// OldBuffer : void* optional -> "pointer"
// NewByteCount : DWORD -> "u32"
// NewBuffer : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NetApiBufferReallocate(
void* OldBuffer,
uint32_t NewByteCount,
void** NewBuffer);
C, "NETAPI32.dll");
// $ffi->NetApiBufferReallocate(OldBuffer, NewByteCount, NewBuffer);
// OldBuffer : void* optional
// NewByteCount : DWORD
// NewBuffer : void** 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 NetApiBufferReallocate(
Pointer OldBuffer, // void* optional
int NewByteCount, // DWORD
Pointer NewBuffer // void** out
);
}@[Link("netapi32")]
lib LibNETAPI32
fun NetApiBufferReallocate = NetApiBufferReallocate(
OldBuffer : Void*, # void* optional
NewByteCount : UInt32, # DWORD
NewBuffer : Void** # void** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NetApiBufferReallocateNative = Uint32 Function(Pointer<Void>, Uint32, Pointer<Void>);
typedef NetApiBufferReallocateDart = int Function(Pointer<Void>, int, Pointer<Void>);
final NetApiBufferReallocate = DynamicLibrary.open('NETAPI32.dll')
.lookupFunction<NetApiBufferReallocateNative, NetApiBufferReallocateDart>('NetApiBufferReallocate');
// OldBuffer : void* optional -> Pointer<Void>
// NewByteCount : DWORD -> Uint32
// NewBuffer : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NetApiBufferReallocate(
OldBuffer: Pointer; // void* optional
NewByteCount: DWORD; // DWORD
NewBuffer: Pointer // void** out
): DWORD; stdcall;
external 'NETAPI32.dll' name 'NetApiBufferReallocate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NetApiBufferReallocate"
c_NetApiBufferReallocate :: Ptr () -> Word32 -> Ptr () -> IO Word32
-- OldBuffer : void* optional -> Ptr ()
-- NewByteCount : DWORD -> Word32
-- NewBuffer : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let netapibufferreallocate =
foreign "NetApiBufferReallocate"
((ptr void) @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* OldBuffer : void* optional -> (ptr void) *)
(* NewByteCount : DWORD -> uint32_t *)
(* NewBuffer : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)
(cffi:defcfun ("NetApiBufferReallocate" net-api-buffer-reallocate :convention :stdcall) :uint32
(old-buffer :pointer) ; void* optional
(new-byte-count :uint32) ; DWORD
(new-buffer :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NetApiBufferReallocate = Win32::API::More->new('NETAPI32',
'DWORD NetApiBufferReallocate(LPVOID OldBuffer, DWORD NewByteCount, LPVOID NewBuffer)');
# my $ret = $NetApiBufferReallocate->Call($OldBuffer, $NewByteCount, $NewBuffer);
# OldBuffer : void* optional -> LPVOID
# NewByteCount : DWORD -> DWORD
# NewBuffer : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f NetApiBufferAllocate — ネットワークAPI関数用のメモリバッファを割り当てる。
- f NetApiBufferFree — ネットワークAPIが割り当てたメモリバッファを解放する。