Win32 API 日本語リファレンス
ホームSystem.Js › JsDefineProperty

JsDefineProperty

関数
プロパティ記述子を使ってプロパティを定義する。
DLLchakra.dll呼出規約winapi

シグネチャ

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

JsErrorCode JsDefineProperty(
    void* object,
    void* propertyId,
    void* propertyDescriptor,
    BOOLEAN* result
);

パラメーター

名前方向
objectvoid*in
propertyIdvoid*in
propertyDescriptorvoid*in
resultBOOLEAN*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*
    out byte result   // BOOLEAN* out
);
<DllImport("chakra.dll", ExactSpelling:=True)>
Public Shared Function JsDefineProperty(
    [object] As IntPtr,   ' void*
    propertyId As IntPtr,   ' void*
    propertyDescriptor As IntPtr,   ' void*
    <Out> ByRef result As Byte   ' 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, out byte 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // JsErrorCode
function 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)。