ホーム › System.Ole › VarI2FromDate
VarI2FromDate
関数DATE型の日付値をSHORT(符号付き2バイト整数)に変換する。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT VarI2FromDate(
DOUBLE dateIn,
SHORT* psOut
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dateIn | DOUBLE | in | 変換する値。 |
| psOut | SHORT* | out | 変換結果の値。 |
戻り値の型: HRESULT
公式ドキュメント
date 値を short 値に変換します。
戻り値
この関数は、次のいずれかの値を返すことがあります。
| 戻り値 | 説明 |
|---|---|
| 成功しました。 | |
| 入力パラメーターが有効な variant 型ではありません。 | |
| 出力パラメーターが指す data が変換先の型に収まりません。 | |
| 引数を指定された型に変換できませんでした。 | |
| 引数のいずれかが有効ではありません。 | |
| 操作を完了するためのメモリが不足しています。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT VarI2FromDate(
DOUBLE dateIn,
SHORT* psOut
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int VarI2FromDate(
double dateIn, // DOUBLE
out short psOut // SHORT* out
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function VarI2FromDate(
dateIn As Double, ' DOUBLE
<Out> ByRef psOut As Short ' SHORT* out
) As Integer
End Function' dateIn : DOUBLE
' psOut : SHORT* out
Declare PtrSafe Function VarI2FromDate Lib "oleaut32" ( _
ByVal dateIn As Double, _
ByRef psOut As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VarI2FromDate = ctypes.windll.oleaut32.VarI2FromDate
VarI2FromDate.restype = ctypes.c_int
VarI2FromDate.argtypes = [
ctypes.c_double, # dateIn : DOUBLE
ctypes.POINTER(ctypes.c_short), # psOut : SHORT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
VarI2FromDate = Fiddle::Function.new(
lib['VarI2FromDate'],
[
Fiddle::TYPE_DOUBLE, # dateIn : DOUBLE
Fiddle::TYPE_VOIDP, # psOut : SHORT* out
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn VarI2FromDate(
dateIn: f64, // DOUBLE
psOut: *mut i16 // SHORT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int VarI2FromDate(double dateIn, out short psOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_VarI2FromDate' -Namespace Win32 -PassThru
# $api::VarI2FromDate(dateIn, psOut)#uselib "OLEAUT32.dll"
#func global VarI2FromDate "VarI2FromDate" double, sptr
; VarI2FromDate dateIn, varptr(psOut) ; 戻り値は stat
; dateIn : DOUBLE -> "double"
; psOut : SHORT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLEAUT32.dll" #cfunc global VarI2FromDate "VarI2FromDate" double, var ; res = VarI2FromDate(dateIn, psOut) ; dateIn : DOUBLE -> "double" ; psOut : SHORT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLEAUT32.dll" #cfunc global VarI2FromDate "VarI2FromDate" double, sptr ; res = VarI2FromDate(dateIn, varptr(psOut)) ; dateIn : DOUBLE -> "double" ; psOut : SHORT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT VarI2FromDate(DOUBLE dateIn, SHORT* psOut) #uselib "OLEAUT32.dll" #cfunc global VarI2FromDate "VarI2FromDate" double, var ; res = VarI2FromDate(dateIn, psOut) ; dateIn : DOUBLE -> "double" ; psOut : SHORT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT VarI2FromDate(DOUBLE dateIn, SHORT* psOut) #uselib "OLEAUT32.dll" #cfunc global VarI2FromDate "VarI2FromDate" double, intptr ; res = VarI2FromDate(dateIn, varptr(psOut)) ; dateIn : DOUBLE -> "double" ; psOut : SHORT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"math"
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procVarI2FromDate = oleaut32.NewProc("VarI2FromDate")
)
// dateIn (DOUBLE), psOut (SHORT* out)
r1, _, err := procVarI2FromDate.Call(
uintptr(math.Float64bits(dateIn)),
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 VarI2FromDate(
dateIn: Double; // DOUBLE
psOut: Pointer // SHORT* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'VarI2FromDate';result := DllCall("OLEAUT32\VarI2FromDate"
, "Double", dateIn ; DOUBLE
, "Ptr", psOut ; SHORT* out
, "Int") ; return: HRESULT●VarI2FromDate(dateIn, psOut) = DLL("OLEAUT32.dll", "int VarI2FromDate(double, void*)")
# 呼び出し: VarI2FromDate(dateIn, psOut)
# dateIn : DOUBLE -> "double"
# psOut : SHORT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "oleaut32" fn VarI2FromDate(
dateIn: f64, // DOUBLE
psOut: [*c]i16 // SHORT* out
) callconv(std.os.windows.WINAPI) i32;proc VarI2FromDate(
dateIn: float64, # DOUBLE
psOut: ptr int16 # SHORT* out
): int32 {.importc: "VarI2FromDate", stdcall, dynlib: "OLEAUT32.dll".}pragma(lib, "oleaut32");
extern(Windows)
int VarI2FromDate(
double dateIn, // DOUBLE
short* psOut // SHORT* out
);ccall((:VarI2FromDate, "OLEAUT32.dll"), stdcall, Int32,
(Float64, Ptr{Int16}),
dateIn, psOut)
# dateIn : DOUBLE -> Float64
# psOut : SHORT* out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t VarI2FromDate(
double dateIn,
int16_t* psOut);
]]
local oleaut32 = ffi.load("oleaut32")
-- oleaut32.VarI2FromDate(dateIn, psOut)
-- dateIn : DOUBLE
-- psOut : SHORT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLEAUT32.dll');
const VarI2FromDate = lib.func('__stdcall', 'VarI2FromDate', 'int32_t', ['double', 'int16_t *']);
// VarI2FromDate(dateIn, psOut)
// dateIn : DOUBLE -> 'double'
// psOut : SHORT* out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLEAUT32.dll", {
VarI2FromDate: { parameters: ["f64", "pointer"], result: "i32" },
});
// lib.symbols.VarI2FromDate(dateIn, psOut)
// dateIn : DOUBLE -> "f64"
// psOut : SHORT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t VarI2FromDate(
double dateIn,
int16_t* psOut);
C, "OLEAUT32.dll");
// $ffi->VarI2FromDate(dateIn, psOut);
// dateIn : DOUBLE
// psOut : SHORT* 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 Oleaut32 extends StdCallLibrary {
Oleaut32 INSTANCE = Native.load("oleaut32", Oleaut32.class);
int VarI2FromDate(
double dateIn, // DOUBLE
ShortByReference psOut // SHORT* out
);
}@[Link("oleaut32")]
lib LibOLEAUT32
fun VarI2FromDate = VarI2FromDate(
dateIn : Float64, # DOUBLE
psOut : Int16* # SHORT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef VarI2FromDateNative = Int32 Function(Double, Pointer<Int16>);
typedef VarI2FromDateDart = int Function(double, Pointer<Int16>);
final VarI2FromDate = DynamicLibrary.open('OLEAUT32.dll')
.lookupFunction<VarI2FromDateNative, VarI2FromDateDart>('VarI2FromDate');
// dateIn : DOUBLE -> Double
// psOut : SHORT* out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function VarI2FromDate(
dateIn: Double; // DOUBLE
psOut: Pointer // SHORT* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'VarI2FromDate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "VarI2FromDate"
c_VarI2FromDate :: CDouble -> Ptr Int16 -> IO Int32
-- dateIn : DOUBLE -> CDouble
-- psOut : SHORT* out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let vari2fromdate =
foreign "VarI2FromDate"
(double @-> (ptr int16_t) @-> returning int32_t)
(* dateIn : DOUBLE -> double *)
(* psOut : SHORT* out -> (ptr int16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)
(cffi:defcfun ("VarI2FromDate" var-i2-from-date :convention :stdcall) :int32
(date-in :double) ; DOUBLE
(ps-out :pointer)) ; SHORT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $VarI2FromDate = Win32::API::More->new('OLEAUT32',
'int VarI2FromDate(double dateIn, LPVOID psOut)');
# my $ret = $VarI2FromDate->Call($dateIn, $psOut);
# dateIn : DOUBLE -> double
# psOut : SHORT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。