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

NetApiBufferAllocate

関数
ネットワークAPI関数用のメモリバッファを割り当てる。
DLLNETAPI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD NetApiBufferAllocate(
    DWORD ByteCount,
    void** Buffer
);

パラメーター

名前方向
ByteCountDWORDin
Buffervoid**out

戻り値の型: DWORD

各言語での呼び出し定義

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

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

NetApiBufferAllocate = ctypes.windll.netapi32.NetApiBufferAllocate
NetApiBufferAllocate.restype = wintypes.DWORD
NetApiBufferAllocate.argtypes = [
    wintypes.DWORD,  # ByteCount : DWORD
    ctypes.c_void_p,  # Buffer : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetApiBufferAllocate = netapi32.NewProc("NetApiBufferAllocate")
)

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