ホーム › System.Ole › VarI4FromR8
VarI4FromR8
関数倍精度浮動小数点数をINT(符号付き4バイト整数)に変換する。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT VarI4FromR8(
DOUBLE dblIn,
INT* plOut
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dblIn | DOUBLE | in |
| plOut | INT* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT VarI4FromR8(
DOUBLE dblIn,
INT* plOut
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int VarI4FromR8(
double dblIn, // DOUBLE
out int plOut // INT* out
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function VarI4FromR8(
dblIn As Double, ' DOUBLE
<Out> ByRef plOut As Integer ' INT* out
) As Integer
End Function' dblIn : DOUBLE
' plOut : INT* out
Declare PtrSafe Function VarI4FromR8 Lib "oleaut32" ( _
ByVal dblIn As Double, _
ByRef plOut As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VarI4FromR8 = ctypes.windll.oleaut32.VarI4FromR8
VarI4FromR8.restype = ctypes.c_int
VarI4FromR8.argtypes = [
ctypes.c_double, # dblIn : DOUBLE
ctypes.POINTER(ctypes.c_int), # plOut : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
VarI4FromR8 = Fiddle::Function.new(
lib['VarI4FromR8'],
[
Fiddle::TYPE_DOUBLE, # dblIn : DOUBLE
Fiddle::TYPE_VOIDP, # plOut : INT* out
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn VarI4FromR8(
dblIn: f64, // DOUBLE
plOut: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int VarI4FromR8(double dblIn, out int plOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_VarI4FromR8' -Namespace Win32 -PassThru
# $api::VarI4FromR8(dblIn, plOut)#uselib "OLEAUT32.dll"
#func global VarI4FromR8 "VarI4FromR8" double, sptr
; VarI4FromR8 dblIn, varptr(plOut) ; 戻り値は stat
; dblIn : DOUBLE -> "double"
; plOut : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLEAUT32.dll" #cfunc global VarI4FromR8 "VarI4FromR8" double, var ; res = VarI4FromR8(dblIn, plOut) ; dblIn : DOUBLE -> "double" ; plOut : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLEAUT32.dll" #cfunc global VarI4FromR8 "VarI4FromR8" double, sptr ; res = VarI4FromR8(dblIn, varptr(plOut)) ; dblIn : DOUBLE -> "double" ; plOut : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT VarI4FromR8(DOUBLE dblIn, INT* plOut) #uselib "OLEAUT32.dll" #cfunc global VarI4FromR8 "VarI4FromR8" double, var ; res = VarI4FromR8(dblIn, plOut) ; dblIn : DOUBLE -> "double" ; plOut : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT VarI4FromR8(DOUBLE dblIn, INT* plOut) #uselib "OLEAUT32.dll" #cfunc global VarI4FromR8 "VarI4FromR8" double, intptr ; res = VarI4FromR8(dblIn, varptr(plOut)) ; dblIn : DOUBLE -> "double" ; plOut : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"math"
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procVarI4FromR8 = oleaut32.NewProc("VarI4FromR8")
)
// dblIn (DOUBLE), plOut (INT* out)
r1, _, err := procVarI4FromR8.Call(
uintptr(math.Float64bits(dblIn)),
uintptr(plOut),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULT
// 注意: float/double 引数は proc.Call では XMM レジスタに渡せません。
// windows.SyscallN(proc.Addr(), math.Float64bits(x), ...) もしくは cgo を使用してください。function VarI4FromR8(
dblIn: Double; // DOUBLE
plOut: Pointer // INT* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'VarI4FromR8';result := DllCall("OLEAUT32\VarI4FromR8"
, "Double", dblIn ; DOUBLE
, "Ptr", plOut ; INT* out
, "Int") ; return: HRESULT●VarI4FromR8(dblIn, plOut) = DLL("OLEAUT32.dll", "int VarI4FromR8(double, void*)")
# 呼び出し: VarI4FromR8(dblIn, plOut)
# dblIn : DOUBLE -> "double"
# plOut : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。