Win32 API 日本語リファレンス
ホームUI.Shell › SHAlloc

SHAlloc

関数
シェルアロケーターでメモリを確保する。
DLLSHELL32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

void* SHAlloc(
    UINT_PTR cb
);

パラメーター

名前方向
cbUINT_PTRin

戻り値の型: void*

各言語での呼び出し定義

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

void* SHAlloc(
    UINT_PTR cb
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern IntPtr SHAlloc(
    UIntPtr cb   // UINT_PTR
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHAlloc(
    cb As UIntPtr   ' UINT_PTR
) As IntPtr
End Function
' cb : UINT_PTR
Declare PtrSafe Function SHAlloc Lib "shell32" ( _
    ByVal cb As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHAlloc = ctypes.windll.shell32.SHAlloc
SHAlloc.restype = ctypes.c_void_p
SHAlloc.argtypes = [
    ctypes.c_size_t,  # cb : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHAlloc = shell32.NewProc("SHAlloc")
)

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