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

VarI2FromR4

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

シグネチャ

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

HRESULT VarI2FromR4(
    FLOAT fltIn,
    SHORT* psOut
);

パラメーター

名前方向
fltInFLOATin
psOutSHORT*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

VarI2FromR4 = ctypes.windll.oleaut32.VarI2FromR4
VarI2FromR4.restype = ctypes.c_int
VarI2FromR4.argtypes = [
    ctypes.c_float,  # fltIn : FLOAT
    ctypes.POINTER(ctypes.c_short),  # psOut : SHORT* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procVarI2FromR4 = oleaut32.NewProc("VarI2FromR4")
)

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