ホーム › Networking.WindowsWebServices › WsAlloc
WsAlloc
関数ヒープからメモリを割り当てる。
シグネチャ
// webservices.dll
#include <windows.h>
HRESULT WsAlloc(
WS_HEAP* heap,
UINT_PTR size,
void** ptr,
WS_ERROR* error // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| heap | WS_HEAP* | in |
| size | UINT_PTR | in |
| ptr | void** | out |
| error | WS_ERROR* | inoptional |
戻り値の型: HRESULT
各言語での呼び出し定義
// webservices.dll
#include <windows.h>
HRESULT WsAlloc(
WS_HEAP* heap,
UINT_PTR size,
void** ptr,
WS_ERROR* error // optional
);[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsAlloc(
ref IntPtr heap, // WS_HEAP*
UIntPtr size, // UINT_PTR
IntPtr ptr, // void** out
IntPtr error // WS_ERROR* optional
);<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsAlloc(
ByRef heap As IntPtr, ' WS_HEAP*
size As UIntPtr, ' UINT_PTR
ptr As IntPtr, ' void** out
[error] As IntPtr ' WS_ERROR* optional
) As Integer
End Function' heap : WS_HEAP*
' size : UINT_PTR
' ptr : void** out
' error : WS_ERROR* optional
Declare PtrSafe Function WsAlloc Lib "webservices" ( _
ByRef heap As LongPtr, _
ByVal size As LongPtr, _
ByVal ptr As LongPtr, _
ByVal error As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WsAlloc = ctypes.windll.webservices.WsAlloc
WsAlloc.restype = ctypes.c_int
WsAlloc.argtypes = [
ctypes.c_void_p, # heap : WS_HEAP*
ctypes.c_size_t, # size : UINT_PTR
ctypes.c_void_p, # ptr : void** out
ctypes.c_void_p, # error : WS_ERROR* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('webservices.dll')
WsAlloc = Fiddle::Function.new(
lib['WsAlloc'],
[
Fiddle::TYPE_VOIDP, # heap : WS_HEAP*
Fiddle::TYPE_UINTPTR_T, # size : UINT_PTR
Fiddle::TYPE_VOIDP, # ptr : void** out
Fiddle::TYPE_VOIDP, # error : WS_ERROR* optional
],
Fiddle::TYPE_INT)#[link(name = "webservices")]
extern "system" {
fn WsAlloc(
heap: *mut isize, // WS_HEAP*
size: usize, // UINT_PTR
ptr: *mut *mut (), // void** out
error: *mut isize // WS_ERROR* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("webservices.dll")]
public static extern int WsAlloc(ref IntPtr heap, UIntPtr size, IntPtr ptr, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsAlloc' -Namespace Win32 -PassThru
# $api::WsAlloc(heap, size, ptr, error)#uselib "webservices.dll"
#func global WsAlloc "WsAlloc" sptr, sptr, sptr, sptr
; WsAlloc heap, size, ptr, error ; 戻り値は stat
; heap : WS_HEAP* -> "sptr"
; size : UINT_PTR -> "sptr"
; ptr : void** out -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "webservices.dll"
#cfunc global WsAlloc "WsAlloc" int, sptr, sptr, int
; res = WsAlloc(heap, size, ptr, error)
; heap : WS_HEAP* -> "int"
; size : UINT_PTR -> "sptr"
; ptr : void** out -> "sptr"
; error : WS_ERROR* optional -> "int"; HRESULT WsAlloc(WS_HEAP* heap, UINT_PTR size, void** ptr, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsAlloc "WsAlloc" int, intptr, intptr, int
; res = WsAlloc(heap, size, ptr, error)
; heap : WS_HEAP* -> "int"
; size : UINT_PTR -> "intptr"
; ptr : void** out -> "intptr"
; error : WS_ERROR* optional -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
webservices = windows.NewLazySystemDLL("webservices.dll")
procWsAlloc = webservices.NewProc("WsAlloc")
)
// heap (WS_HEAP*), size (UINT_PTR), ptr (void** out), error (WS_ERROR* optional)
r1, _, err := procWsAlloc.Call(
uintptr(heap),
uintptr(size),
uintptr(ptr),
uintptr(error),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WsAlloc(
heap: Pointer; // WS_HEAP*
size: NativeUInt; // UINT_PTR
ptr: Pointer; // void** out
error: Pointer // WS_ERROR* optional
): Integer; stdcall;
external 'webservices.dll' name 'WsAlloc';result := DllCall("webservices\WsAlloc"
, "Ptr", heap ; WS_HEAP*
, "UPtr", size ; UINT_PTR
, "Ptr", ptr ; void** out
, "Ptr", error ; WS_ERROR* optional
, "Int") ; return: HRESULT●WsAlloc(heap, size, ptr, error) = DLL("webservices.dll", "int WsAlloc(void*, int, void*, void*)")
# 呼び出し: WsAlloc(heap, size, ptr, error)
# heap : WS_HEAP* -> "void*"
# size : UINT_PTR -> "int"
# ptr : void** out -> "void*"
# error : WS_ERROR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。