ホーム › 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 | 確保元となるWS_HEAPヒープオブジェクトへのポインタ。 |
| size | UINT_PTR | in | 確保するメモリのバイト数を指定する。ヒープの最大サイズ制限を超えると失敗する。 |
| ptr | void** | out | 確保されたメモリブロックの先頭アドレスを受け取る出力ポインタ。 |
| error | WS_ERROR* | inoptional | 詳細なエラー情報を格納するWS_ERRORオブジェクト。NULL可。 |
戻り値の型: 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 varptr(heap), size, ptr, varptr(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" var, sptr, sptr, var ; res = WsAlloc(heap, size, ptr, error) ; heap : WS_HEAP* -> "var" ; size : UINT_PTR -> "sptr" ; ptr : void** out -> "sptr" ; error : WS_ERROR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "webservices.dll" #cfunc global WsAlloc "WsAlloc" sptr, sptr, sptr, sptr ; res = WsAlloc(varptr(heap), size, ptr, varptr(error)) ; heap : WS_HEAP* -> "sptr" ; size : UINT_PTR -> "sptr" ; ptr : void** out -> "sptr" ; error : WS_ERROR* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT WsAlloc(WS_HEAP* heap, UINT_PTR size, void** ptr, WS_ERROR* error) #uselib "webservices.dll" #cfunc global WsAlloc "WsAlloc" var, intptr, intptr, var ; res = WsAlloc(heap, size, ptr, error) ; heap : WS_HEAP* -> "var" ; size : UINT_PTR -> "intptr" ; ptr : void** out -> "intptr" ; error : WS_ERROR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT WsAlloc(WS_HEAP* heap, UINT_PTR size, void** ptr, WS_ERROR* error) #uselib "webservices.dll" #cfunc global WsAlloc "WsAlloc" intptr, intptr, intptr, intptr ; res = WsAlloc(varptr(heap), size, ptr, varptr(error)) ; heap : WS_HEAP* -> "intptr" ; size : UINT_PTR -> "intptr" ; ptr : void** out -> "intptr" ; error : WS_ERROR* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
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)。const std = @import("std");
extern "webservices" fn WsAlloc(
heap: [*c]isize, // WS_HEAP*
size: usize, // UINT_PTR
ptr: ?*anyopaque, // void** out
error: [*c]isize // WS_ERROR* optional
) callconv(std.os.windows.WINAPI) i32;proc WsAlloc(
heap: ptr int, # WS_HEAP*
size: uint, # UINT_PTR
`ptr`: pointer, # void** out
error: ptr int # WS_ERROR* optional
): int32 {.importc: "WsAlloc", stdcall, dynlib: "webservices.dll".}pragma(lib, "webservices");
extern(Windows)
int WsAlloc(
ptrdiff_t* heap, // WS_HEAP*
size_t size, // UINT_PTR
void** ptr, // void** out
ptrdiff_t* error // WS_ERROR* optional
);ccall((:WsAlloc, "webservices.dll"), stdcall, Int32,
(Ptr{Int}, Csize_t, Ptr{Cvoid}, Ptr{Int}),
heap, size, ptr, error)
# heap : WS_HEAP* -> Ptr{Int}
# size : UINT_PTR -> Csize_t
# ptr : void** out -> Ptr{Cvoid}
# error : WS_ERROR* optional -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WsAlloc(
intptr_t* heap,
uintptr_t size,
void** ptr,
intptr_t* error);
]]
local webservices = ffi.load("webservices")
-- webservices.WsAlloc(heap, size, ptr, error)
-- heap : WS_HEAP*
-- size : UINT_PTR
-- ptr : void** out
-- error : WS_ERROR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('webservices.dll');
const WsAlloc = lib.func('__stdcall', 'WsAlloc', 'int32_t', ['intptr_t *', 'uintptr_t', 'void *', 'intptr_t *']);
// WsAlloc(heap, size, ptr, error)
// heap : WS_HEAP* -> 'intptr_t *'
// size : UINT_PTR -> 'uintptr_t'
// ptr : void** out -> 'void *'
// error : WS_ERROR* optional -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("webservices.dll", {
WsAlloc: { parameters: ["pointer", "usize", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WsAlloc(heap, size, ptr, error)
// heap : WS_HEAP* -> "pointer"
// size : UINT_PTR -> "usize"
// ptr : void** out -> "pointer"
// error : WS_ERROR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WsAlloc(
intptr_t* heap,
size_t size,
void** ptr,
intptr_t* error);
C, "webservices.dll");
// $ffi->WsAlloc(heap, size, ptr, error);
// heap : WS_HEAP*
// size : UINT_PTR
// ptr : void** out
// error : WS_ERROR* optional
// 構造体/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 Webservices extends StdCallLibrary {
Webservices INSTANCE = Native.load("webservices", Webservices.class);
int WsAlloc(
LongByReference heap, // WS_HEAP*
long size, // UINT_PTR
Pointer ptr, // void** out
LongByReference error // WS_ERROR* optional
);
}@[Link("webservices")]
lib Libwebservices
fun WsAlloc = WsAlloc(
heap : LibC::SSizeT*, # WS_HEAP*
size : LibC::SizeT, # UINT_PTR
ptr : Void**, # void** out
error : LibC::SSizeT* # WS_ERROR* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WsAllocNative = Int32 Function(Pointer<IntPtr>, UintPtr, Pointer<Void>, Pointer<IntPtr>);
typedef WsAllocDart = int Function(Pointer<IntPtr>, int, Pointer<Void>, Pointer<IntPtr>);
final WsAlloc = DynamicLibrary.open('webservices.dll')
.lookupFunction<WsAllocNative, WsAllocDart>('WsAlloc');
// heap : WS_HEAP* -> Pointer<IntPtr>
// size : UINT_PTR -> UintPtr
// ptr : void** out -> Pointer<Void>
// error : WS_ERROR* optional -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WsAlloc"
c_WsAlloc :: Ptr CIntPtr -> CUIntPtr -> Ptr () -> Ptr CIntPtr -> IO Int32
-- heap : WS_HEAP* -> Ptr CIntPtr
-- size : UINT_PTR -> CUIntPtr
-- ptr : void** out -> Ptr ()
-- error : WS_ERROR* optional -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wsalloc =
foreign "WsAlloc"
((ptr intptr_t) @-> size_t @-> (ptr void) @-> (ptr intptr_t) @-> returning int32_t)
(* heap : WS_HEAP* -> (ptr intptr_t) *)
(* size : UINT_PTR -> size_t *)
(* ptr : void** out -> (ptr void) *)
(* error : WS_ERROR* optional -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library webservices (t "webservices.dll"))
(cffi:use-foreign-library webservices)
(cffi:defcfun ("WsAlloc" ws-alloc :convention :stdcall) :int32
(heap :pointer) ; WS_HEAP*
(size :uint64) ; UINT_PTR
(ptr :pointer) ; void** out
(error :pointer)) ; WS_ERROR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WsAlloc = Win32::API::More->new('webservices',
'int WsAlloc(LPVOID heap, WPARAM size, LPVOID ptr, LPVOID error)');
# my $ret = $WsAlloc->Call($heap, $size, $ptr, $error);
# heap : WS_HEAP* -> LPVOID
# size : UINT_PTR -> WPARAM
# ptr : void** out -> LPVOID
# error : WS_ERROR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。