JsDefineProperty
関数プロパティ記述子を使ってプロパティを定義する。
シグネチャ
// chakra.dll
#include <windows.h>
JsErrorCode JsDefineProperty(
void* object,
void* propertyId,
void* propertyDescriptor,
BOOLEAN* result
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| object | void* | in | プロパティを定義する対象のオブジェクト。 |
| propertyId | void* | in | 定義するプロパティの識別子(JsPropertyIdRef)。 |
| propertyDescriptor | void* | in | value/writable/get/set等を持つプロパティ記述子オブジェクト。 |
| result | BOOLEAN* | out | 定義操作が成功したかを受け取る変数へのポインタ。 |
戻り値の型: JsErrorCode
各言語での呼び出し定義
// chakra.dll
#include <windows.h>
JsErrorCode JsDefineProperty(
void* object,
void* propertyId,
void* propertyDescriptor,
BOOLEAN* result
);[DllImport("chakra.dll", ExactSpelling = true)]
static extern uint JsDefineProperty(
IntPtr object, // void*
IntPtr propertyId, // void*
IntPtr propertyDescriptor, // void*
[MarshalAs(UnmanagedType.U1)] out bool result // BOOLEAN* out
);<DllImport("chakra.dll", ExactSpelling:=True)>
Public Shared Function JsDefineProperty(
[object] As IntPtr, ' void*
propertyId As IntPtr, ' void*
propertyDescriptor As IntPtr, ' void*
<MarshalAs(UnmanagedType.U1)> <Out> ByRef result As Boolean ' BOOLEAN* out
) As UInteger
End Function' object : void*
' propertyId : void*
' propertyDescriptor : void*
' result : BOOLEAN* out
Declare PtrSafe Function JsDefineProperty Lib "chakra" ( _
ByVal object As LongPtr, _
ByVal propertyId As LongPtr, _
ByVal propertyDescriptor As LongPtr, _
ByRef result As Byte) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
JsDefineProperty = ctypes.windll.chakra.JsDefineProperty
JsDefineProperty.restype = wintypes.DWORD
JsDefineProperty.argtypes = [
ctypes.POINTER(None), # object : void*
ctypes.POINTER(None), # propertyId : void*
ctypes.POINTER(None), # propertyDescriptor : void*
ctypes.POINTER(ctypes.c_byte), # result : BOOLEAN* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('chakra.dll')
JsDefineProperty = Fiddle::Function.new(
lib['JsDefineProperty'],
[
Fiddle::TYPE_VOIDP, # object : void*
Fiddle::TYPE_VOIDP, # propertyId : void*
Fiddle::TYPE_VOIDP, # propertyDescriptor : void*
Fiddle::TYPE_VOIDP, # result : BOOLEAN* out
],
-Fiddle::TYPE_INT)#[link(name = "chakra")]
extern "system" {
fn JsDefineProperty(
object: *mut (), // void*
propertyId: *mut (), // void*
propertyDescriptor: *mut (), // void*
result: *mut u8 // BOOLEAN* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("chakra.dll")]
public static extern uint JsDefineProperty(IntPtr object, IntPtr propertyId, IntPtr propertyDescriptor, [MarshalAs(UnmanagedType.U1)] out bool result);
"@
$api = Add-Type -MemberDefinition $sig -Name 'chakra_JsDefineProperty' -Namespace Win32 -PassThru
# $api::JsDefineProperty(object, propertyId, propertyDescriptor, result)#uselib "chakra.dll"
#func global JsDefineProperty "JsDefineProperty" sptr, sptr, sptr, sptr
; JsDefineProperty object, propertyId, propertyDescriptor, varptr(result) ; 戻り値は stat
; object : void* -> "sptr"
; propertyId : void* -> "sptr"
; propertyDescriptor : void* -> "sptr"
; result : BOOLEAN* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "chakra.dll" #cfunc global JsDefineProperty "JsDefineProperty" sptr, sptr, sptr, var ; res = JsDefineProperty(object, propertyId, propertyDescriptor, result) ; object : void* -> "sptr" ; propertyId : void* -> "sptr" ; propertyDescriptor : void* -> "sptr" ; result : BOOLEAN* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "chakra.dll" #cfunc global JsDefineProperty "JsDefineProperty" sptr, sptr, sptr, sptr ; res = JsDefineProperty(object, propertyId, propertyDescriptor, varptr(result)) ; object : void* -> "sptr" ; propertyId : void* -> "sptr" ; propertyDescriptor : void* -> "sptr" ; result : BOOLEAN* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; JsErrorCode JsDefineProperty(void* object, void* propertyId, void* propertyDescriptor, BOOLEAN* result) #uselib "chakra.dll" #cfunc global JsDefineProperty "JsDefineProperty" intptr, intptr, intptr, var ; res = JsDefineProperty(object, propertyId, propertyDescriptor, result) ; object : void* -> "intptr" ; propertyId : void* -> "intptr" ; propertyDescriptor : void* -> "intptr" ; result : BOOLEAN* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; JsErrorCode JsDefineProperty(void* object, void* propertyId, void* propertyDescriptor, BOOLEAN* result) #uselib "chakra.dll" #cfunc global JsDefineProperty "JsDefineProperty" intptr, intptr, intptr, intptr ; res = JsDefineProperty(object, propertyId, propertyDescriptor, varptr(result)) ; object : void* -> "intptr" ; propertyId : void* -> "intptr" ; propertyDescriptor : void* -> "intptr" ; result : BOOLEAN* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
chakra = windows.NewLazySystemDLL("chakra.dll")
procJsDefineProperty = chakra.NewProc("JsDefineProperty")
)
// object (void*), propertyId (void*), propertyDescriptor (void*), result (BOOLEAN* out)
r1, _, err := procJsDefineProperty.Call(
uintptr(object),
uintptr(propertyId),
uintptr(propertyDescriptor),
uintptr(result),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // JsErrorCodefunction JsDefineProperty(
object: Pointer; // void*
propertyId: Pointer; // void*
propertyDescriptor: Pointer; // void*
result: Pointer // BOOLEAN* out
): DWORD; stdcall;
external 'chakra.dll' name 'JsDefineProperty';result := DllCall("chakra\JsDefineProperty"
, "Ptr", object ; void*
, "Ptr", propertyId ; void*
, "Ptr", propertyDescriptor ; void*
, "Ptr", result ; BOOLEAN* out
, "UInt") ; return: JsErrorCode●JsDefineProperty(object, propertyId, propertyDescriptor, result) = DLL("chakra.dll", "dword JsDefineProperty(void*, void*, void*, void*)")
# 呼び出し: JsDefineProperty(object, propertyId, propertyDescriptor, result)
# object : void* -> "void*"
# propertyId : void* -> "void*"
# propertyDescriptor : void* -> "void*"
# result : BOOLEAN* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "chakra" fn JsDefineProperty(
object: ?*anyopaque, // void*
propertyId: ?*anyopaque, // void*
propertyDescriptor: ?*anyopaque, // void*
result: [*c]u8 // BOOLEAN* out
) callconv(std.os.windows.WINAPI) u32;proc JsDefineProperty(
`object`: pointer, # void*
propertyId: pointer, # void*
propertyDescriptor: pointer, # void*
result: ptr uint8 # BOOLEAN* out
): uint32 {.importc: "JsDefineProperty", stdcall, dynlib: "chakra.dll".}pragma(lib, "chakra");
extern(Windows)
uint JsDefineProperty(
void* object, // void*
void* propertyId, // void*
void* propertyDescriptor, // void*
ubyte* result // BOOLEAN* out
);ccall((:JsDefineProperty, "chakra.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{UInt8}),
object, propertyId, propertyDescriptor, result)
# object : void* -> Ptr{Cvoid}
# propertyId : void* -> Ptr{Cvoid}
# propertyDescriptor : void* -> Ptr{Cvoid}
# result : BOOLEAN* out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t JsDefineProperty(
void* object,
void* propertyId,
void* propertyDescriptor,
uint8_t* result);
]]
local chakra = ffi.load("chakra")
-- chakra.JsDefineProperty(object, propertyId, propertyDescriptor, result)
-- object : void*
-- propertyId : void*
-- propertyDescriptor : void*
-- result : BOOLEAN* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('chakra.dll');
const JsDefineProperty = lib.func('__stdcall', 'JsDefineProperty', 'uint32_t', ['void *', 'void *', 'void *', 'uint8_t *']);
// JsDefineProperty(object, propertyId, propertyDescriptor, result)
// object : void* -> 'void *'
// propertyId : void* -> 'void *'
// propertyDescriptor : void* -> 'void *'
// result : BOOLEAN* out -> 'uint8_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("chakra.dll", {
JsDefineProperty: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.JsDefineProperty(object, propertyId, propertyDescriptor, result)
// object : void* -> "pointer"
// propertyId : void* -> "pointer"
// propertyDescriptor : void* -> "pointer"
// result : BOOLEAN* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t JsDefineProperty(
void* object,
void* propertyId,
void* propertyDescriptor,
uint8_t* result);
C, "chakra.dll");
// $ffi->JsDefineProperty(object, propertyId, propertyDescriptor, result);
// object : void*
// propertyId : void*
// propertyDescriptor : void*
// result : BOOLEAN* out
// 構造体/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 Chakra extends StdCallLibrary {
Chakra INSTANCE = Native.load("chakra", Chakra.class);
int JsDefineProperty(
Pointer object, // void*
Pointer propertyId, // void*
Pointer propertyDescriptor, // void*
ByteByReference result // BOOLEAN* out
);
}@[Link("chakra")]
lib Libchakra
fun JsDefineProperty = JsDefineProperty(
object : Void*, # void*
propertyId : Void*, # void*
propertyDescriptor : Void*, # void*
result : UInt8* # BOOLEAN* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef JsDefinePropertyNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>);
typedef JsDefinePropertyDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>);
final JsDefineProperty = DynamicLibrary.open('chakra.dll')
.lookupFunction<JsDefinePropertyNative, JsDefinePropertyDart>('JsDefineProperty');
// object : void* -> Pointer<Void>
// propertyId : void* -> Pointer<Void>
// propertyDescriptor : void* -> Pointer<Void>
// result : BOOLEAN* out -> Pointer<Uint8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function JsDefineProperty(
object: Pointer; // void*
propertyId: Pointer; // void*
propertyDescriptor: Pointer; // void*
result: Pointer // BOOLEAN* out
): DWORD; stdcall;
external 'chakra.dll' name 'JsDefineProperty';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "JsDefineProperty"
c_JsDefineProperty :: Ptr () -> Ptr () -> Ptr () -> Ptr Word8 -> IO Word32
-- object : void* -> Ptr ()
-- propertyId : void* -> Ptr ()
-- propertyDescriptor : void* -> Ptr ()
-- result : BOOLEAN* out -> Ptr Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let jsdefineproperty =
foreign "JsDefineProperty"
((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> returning uint32_t)
(* object : void* -> (ptr void) *)
(* propertyId : void* -> (ptr void) *)
(* propertyDescriptor : void* -> (ptr void) *)
(* result : BOOLEAN* out -> (ptr uint8_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library chakra (t "chakra.dll"))
(cffi:use-foreign-library chakra)
(cffi:defcfun ("JsDefineProperty" js-define-property :convention :stdcall) :uint32
(object :pointer) ; void*
(property-id :pointer) ; void*
(property-descriptor :pointer) ; void*
(result :pointer)) ; BOOLEAN* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $JsDefineProperty = Win32::API::More->new('chakra',
'DWORD JsDefineProperty(LPVOID object, LPVOID propertyId, LPVOID propertyDescriptor, LPVOID result)');
# my $ret = $JsDefineProperty->Call($object, $propertyId, $propertyDescriptor, $result);
# object : void* -> LPVOID
# propertyId : void* -> LPVOID
# propertyDescriptor : void* -> LPVOID
# result : BOOLEAN* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型