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