Win32 API 日本語リファレンス
ホームNetworking.Ldap › ber_alloc_t

ber_alloc_t

関数
新しいBER要素を割り当てて作成する。
DLLWLDAP32.dll呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

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

BerElement* ber_alloc_t(
    INT options
);

パラメーター

名前方向説明
optionsINTinBerElement生成時の動作オプション。LBER_USE_DER等のモードフラグを指定する。

戻り値の型: BerElement*

各言語での呼び出し定義

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

BerElement* ber_alloc_t(
    INT options
);
[DllImport("WLDAP32.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ber_alloc_t(
    int options   // INT
);
<DllImport("WLDAP32.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ber_alloc_t(
    options As Integer   ' INT
) As IntPtr
End Function
' options : INT
Declare PtrSafe Function ber_alloc_t Lib "wldap32" ( _
    ByVal options As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ber_alloc_t = ctypes.cdll.wldap32.ber_alloc_t
ber_alloc_t.restype = ctypes.c_void_p
ber_alloc_t.argtypes = [
    ctypes.c_int,  # options : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WLDAP32.dll')
ber_alloc_t = Fiddle::Function.new(
  lib['ber_alloc_t'],
  [
    Fiddle::TYPE_INT,  # options : INT
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "wldap32")]
extern "C" {
    fn ber_alloc_t(
        options: i32  // INT
    ) -> *mut BerElement;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WLDAP32.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ber_alloc_t(int options);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ber_alloc_t' -Namespace Win32 -PassThru
# $api::ber_alloc_t(options)
#uselib "WLDAP32.dll"
#func global ber_alloc_t "ber_alloc_t" sptr
; ber_alloc_t options   ; 戻り値は stat
; options : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WLDAP32.dll"
#cfunc global ber_alloc_t "ber_alloc_t" int
; res = ber_alloc_t(options)
; options : INT -> "int"
; BerElement* ber_alloc_t(INT options)
#uselib "WLDAP32.dll"
#cfunc global ber_alloc_t "ber_alloc_t" int
; res = ber_alloc_t(options)
; options : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procber_alloc_t = wldap32.NewProc("ber_alloc_t")
)

// options (INT)
r1, _, err := procber_alloc_t.Call(
	uintptr(options),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BerElement*
function ber_alloc_t(
  options: Integer   // INT
): Pointer; cdecl;
  external 'WLDAP32.dll' name 'ber_alloc_t';
result := DllCall("WLDAP32\ber_alloc_t"
    , "Int", options   ; INT
    , "Cdecl Ptr")   ; return: BerElement*
●ber_alloc_t(options) = DLL("WLDAP32.dll", "void* ber_alloc_t(int)")
# 呼び出し: ber_alloc_t(options)
# options : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
const std = @import("std");

extern "wldap32" fn ber_alloc_t(
    options: i32 // INT
) callconv(.c) [*c]BerElement;
proc ber_alloc_t(
    options: int32  # INT
): ptr BerElement {.importc: "ber_alloc_t", cdecl, dynlib: "WLDAP32.dll".}
pragma(lib, "wldap32");
extern(C)
BerElement* ber_alloc_t(
    int options   // INT
);
ccall((:ber_alloc_t, "WLDAP32.dll"), Ptr{BerElement},
      (Int32,),
      options)
# options : INT -> Int32
local ffi = require("ffi")
ffi.cdef[[
void* ber_alloc_t(
    int32_t options);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ber_alloc_t(options)
-- options : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ber_alloc_t = lib.func('__cdecl', 'ber_alloc_t', 'void *', ['int32_t']);
// ber_alloc_t(options)
// options : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WLDAP32.dll", {
  ber_alloc_t: { parameters: ["i32"], result: "pointer" },
});
// lib.symbols.ber_alloc_t(options)
// options : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* ber_alloc_t(
    int32_t options);
C, "WLDAP32.dll");
// $ffi->ber_alloc_t(options);
// options : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Wldap32 extends Library {
    Wldap32 INSTANCE = Native.load("wldap32", Wldap32.class);
    Pointer ber_alloc_t(
        int options   // INT
    );
}
@[Link("wldap32")]
lib LibWLDAP32
  fun ber_alloc_t = ber_alloc_t(
    options : Int32   # INT
  ) : BerElement*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ber_alloc_tNative = Pointer<Void> Function(Int32);
typedef ber_alloc_tDart = Pointer<Void> Function(int);
final ber_alloc_t = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ber_alloc_tNative, ber_alloc_tDart>('ber_alloc_t');
// options : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ber_alloc_t(
  options: Integer   // INT
): Pointer; cdecl;
  external 'WLDAP32.dll' name 'ber_alloc_t';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ber_alloc_t"
  c_ber_alloc_t :: Int32 -> IO (Ptr ())
-- options : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ber_alloc_t =
  foreign "ber_alloc_t"
    (int32_t @-> returning (ptr void))
(* options : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ber_alloc_t" ber-alloc-t :convention :cdecl) :pointer
  (options :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ber_alloc_t = Win32::API::More->new('WLDAP32',
    'LPVOID ber_alloc_t(int options)');
# my $ret = $ber_alloc_t->Call($options);
# options : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型