SHAlloc
関数シェルアロケーターでメモリを確保する。
シグネチャ
// SHELL32.dll
#include <windows.h>
void* SHAlloc(
UINT_PTR cb
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| cb | UINT_PTR | in | 割り当てるメモリのバイト数。 |
戻り値の型: void*
公式ドキュメント
シェルのヒープからメモリを割り当てます。
戻り値
型: LPVOID
割り当てられたメモリへのポインター。
解説(Remarks)
このメモリは SHFree を呼び出すことで解放できます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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)。const std = @import("std");
extern "shell32" fn SHAlloc(
cb: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc SHAlloc(
cb: uint # UINT_PTR
): pointer {.importc: "SHAlloc", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void* SHAlloc(
size_t cb // UINT_PTR
);ccall((:SHAlloc, "SHELL32.dll"), stdcall, Ptr{Cvoid},
(Csize_t,),
cb)
# cb : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* SHAlloc(
uintptr_t cb);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHAlloc(cb)
-- cb : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHAlloc = lib.func('__stdcall', 'SHAlloc', 'void *', ['uintptr_t']);
// SHAlloc(cb)
// cb : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHAlloc: { parameters: ["usize"], result: "pointer" },
});
// lib.symbols.SHAlloc(cb)
// cb : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* SHAlloc(
size_t cb);
C, "SHELL32.dll");
// $ffi->SHAlloc(cb);
// cb : UINT_PTR
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
Pointer SHAlloc(
long cb // UINT_PTR
);
}@[Link("shell32")]
lib LibSHELL32
fun SHAlloc = SHAlloc(
cb : LibC::SizeT # UINT_PTR
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHAllocNative = Pointer<Void> Function(UintPtr);
typedef SHAllocDart = Pointer<Void> Function(int);
final SHAlloc = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHAllocNative, SHAllocDart>('SHAlloc');
// cb : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHAlloc(
cb: NativeUInt // UINT_PTR
): Pointer; stdcall;
external 'SHELL32.dll' name 'SHAlloc';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHAlloc"
c_SHAlloc :: CUIntPtr -> IO (Ptr ())
-- cb : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shalloc =
foreign "SHAlloc"
(size_t @-> returning (ptr void))
(* cb : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHAlloc" shalloc :convention :stdcall) :pointer
(cb :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHAlloc = Win32::API::More->new('SHELL32',
'LPVOID SHAlloc(WPARAM cb)');
# my $ret = $SHAlloc->Call($cb);
# cb : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。