ホーム › Networking.ActiveDirectory › AllocADsMem
AllocADsMem
関数ADSI用のメモリブロックを確保する。
シグネチャ
// ACTIVEDS.dll
#include <windows.h>
void* AllocADsMem(
DWORD cb
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| cb | DWORD | in | 確保するメモリのバイト数。ADSI用のヒープから割り当てられゼロ初期化される。 |
戻り値の型: void*
各言語での呼び出し定義
// ACTIVEDS.dll
#include <windows.h>
void* AllocADsMem(
DWORD cb
);[DllImport("ACTIVEDS.dll", ExactSpelling = true)]
static extern IntPtr AllocADsMem(
uint cb // DWORD
);<DllImport("ACTIVEDS.dll", ExactSpelling:=True)>
Public Shared Function AllocADsMem(
cb As UInteger ' DWORD
) As IntPtr
End Function' cb : DWORD
Declare PtrSafe Function AllocADsMem Lib "activeds" ( _
ByVal cb As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AllocADsMem = ctypes.windll.activeds.AllocADsMem
AllocADsMem.restype = ctypes.c_void_p
AllocADsMem.argtypes = [
wintypes.DWORD, # cb : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ACTIVEDS.dll')
AllocADsMem = Fiddle::Function.new(
lib['AllocADsMem'],
[
-Fiddle::TYPE_INT, # cb : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "activeds")]
extern "system" {
fn AllocADsMem(
cb: u32 // DWORD
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ACTIVEDS.dll")]
public static extern IntPtr AllocADsMem(uint cb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ACTIVEDS_AllocADsMem' -Namespace Win32 -PassThru
# $api::AllocADsMem(cb)#uselib "ACTIVEDS.dll"
#func global AllocADsMem "AllocADsMem" sptr
; AllocADsMem cb ; 戻り値は stat
; cb : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ACTIVEDS.dll"
#cfunc global AllocADsMem "AllocADsMem" int
; res = AllocADsMem(cb)
; cb : DWORD -> "int"; void* AllocADsMem(DWORD cb)
#uselib "ACTIVEDS.dll"
#cfunc global AllocADsMem "AllocADsMem" int
; res = AllocADsMem(cb)
; cb : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
activeds = windows.NewLazySystemDLL("ACTIVEDS.dll")
procAllocADsMem = activeds.NewProc("AllocADsMem")
)
// cb (DWORD)
r1, _, err := procAllocADsMem.Call(
uintptr(cb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function AllocADsMem(
cb: DWORD // DWORD
): Pointer; stdcall;
external 'ACTIVEDS.dll' name 'AllocADsMem';result := DllCall("ACTIVEDS\AllocADsMem"
, "UInt", cb ; DWORD
, "Ptr") ; return: void*●AllocADsMem(cb) = DLL("ACTIVEDS.dll", "void* AllocADsMem(dword)")
# 呼び出し: AllocADsMem(cb)
# cb : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "activeds" fn AllocADsMem(
cb: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc AllocADsMem(
cb: uint32 # DWORD
): pointer {.importc: "AllocADsMem", stdcall, dynlib: "ACTIVEDS.dll".}pragma(lib, "activeds");
extern(Windows)
void* AllocADsMem(
uint cb // DWORD
);ccall((:AllocADsMem, "ACTIVEDS.dll"), stdcall, Ptr{Cvoid},
(UInt32,),
cb)
# cb : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* AllocADsMem(
uint32_t cb);
]]
local activeds = ffi.load("activeds")
-- activeds.AllocADsMem(cb)
-- cb : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ACTIVEDS.dll');
const AllocADsMem = lib.func('__stdcall', 'AllocADsMem', 'void *', ['uint32_t']);
// AllocADsMem(cb)
// cb : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ACTIVEDS.dll", {
AllocADsMem: { parameters: ["u32"], result: "pointer" },
});
// lib.symbols.AllocADsMem(cb)
// cb : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* AllocADsMem(
uint32_t cb);
C, "ACTIVEDS.dll");
// $ffi->AllocADsMem(cb);
// cb : DWORD
// 構造体/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 Activeds extends StdCallLibrary {
Activeds INSTANCE = Native.load("activeds", Activeds.class);
Pointer AllocADsMem(
int cb // DWORD
);
}@[Link("activeds")]
lib LibACTIVEDS
fun AllocADsMem = AllocADsMem(
cb : UInt32 # DWORD
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AllocADsMemNative = Pointer<Void> Function(Uint32);
typedef AllocADsMemDart = Pointer<Void> Function(int);
final AllocADsMem = DynamicLibrary.open('ACTIVEDS.dll')
.lookupFunction<AllocADsMemNative, AllocADsMemDart>('AllocADsMem');
// cb : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AllocADsMem(
cb: DWORD // DWORD
): Pointer; stdcall;
external 'ACTIVEDS.dll' name 'AllocADsMem';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AllocADsMem"
c_AllocADsMem :: Word32 -> IO (Ptr ())
-- cb : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let allocadsmem =
foreign "AllocADsMem"
(uint32_t @-> returning (ptr void))
(* cb : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library activeds (t "ACTIVEDS.dll"))
(cffi:use-foreign-library activeds)
(cffi:defcfun ("AllocADsMem" alloc-ads-mem :convention :stdcall) :pointer
(cb :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AllocADsMem = Win32::API::More->new('ACTIVEDS',
'LPVOID AllocADsMem(DWORD cb)');
# my $ret = $AllocADsMem->Call($cb);
# cb : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。