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

VarI4FromR4

関数
単精度浮動小数点数をINT(符号付き4バイト整数)に変換する。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT VarI4FromR4(
    FLOAT fltIn,
    INT* plOut
);

パラメーター

名前方向
fltInFLOATin
plOutINT*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT VarI4FromR4(
    FLOAT fltIn,
    INT* plOut
);
[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int VarI4FromR4(
    float fltIn,   // FLOAT
    out int plOut   // INT* out
);
<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function VarI4FromR4(
    fltIn As Single,   ' FLOAT
    <Out> ByRef plOut As Integer   ' INT* out
) As Integer
End Function
' fltIn : FLOAT
' plOut : INT* out
Declare PtrSafe Function VarI4FromR4 Lib "oleaut32" ( _
    ByVal fltIn As Single, _
    ByRef plOut As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

VarI4FromR4 = ctypes.windll.oleaut32.VarI4FromR4
VarI4FromR4.restype = ctypes.c_int
VarI4FromR4.argtypes = [
    ctypes.c_float,  # fltIn : FLOAT
    ctypes.POINTER(ctypes.c_int),  # plOut : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLEAUT32.dll')
VarI4FromR4 = Fiddle::Function.new(
  lib['VarI4FromR4'],
  [
    Fiddle::TYPE_FLOAT,  # fltIn : FLOAT
    Fiddle::TYPE_VOIDP,  # plOut : INT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "oleaut32")]
extern "system" {
    fn VarI4FromR4(
        fltIn: f32,  // FLOAT
        plOut: *mut i32  // INT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int VarI4FromR4(float fltIn, out int plOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_VarI4FromR4' -Namespace Win32 -PassThru
# $api::VarI4FromR4(fltIn, plOut)
#uselib "OLEAUT32.dll"
#func global VarI4FromR4 "VarI4FromR4" float, sptr
; VarI4FromR4 fltIn, varptr(plOut)   ; 戻り値は stat
; fltIn : FLOAT -> "float"
; plOut : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLEAUT32.dll"
#cfunc global VarI4FromR4 "VarI4FromR4" float, var
; res = VarI4FromR4(fltIn, plOut)
; fltIn : FLOAT -> "float"
; plOut : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT VarI4FromR4(FLOAT fltIn, INT* plOut)
#uselib "OLEAUT32.dll"
#cfunc global VarI4FromR4 "VarI4FromR4" float, var
; res = VarI4FromR4(fltIn, plOut)
; fltIn : FLOAT -> "float"
; plOut : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"math"
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procVarI4FromR4 = oleaut32.NewProc("VarI4FromR4")
)

// fltIn (FLOAT), plOut (INT* out)
r1, _, err := procVarI4FromR4.Call(
	uintptr(math.Float32bits(fltIn)),
	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 VarI4FromR4(
  fltIn: Single;   // FLOAT
  plOut: Pointer   // INT* out
): Integer; stdcall;
  external 'OLEAUT32.dll' name 'VarI4FromR4';
result := DllCall("OLEAUT32\VarI4FromR4"
    , "Float", fltIn   ; FLOAT
    , "Ptr", plOut   ; INT* out
    , "Int")   ; return: HRESULT
●VarI4FromR4(fltIn, plOut) = DLL("OLEAUT32.dll", "int VarI4FromR4(float, void*)")
# 呼び出し: VarI4FromR4(fltIn, plOut)
# fltIn : FLOAT -> "float"
# plOut : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。