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

VarI1FromI2

関数
符号付き2バイト整数を符号付き1バイト整数に変換する。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT VarI1FromI2(
    SHORT uiIn,
    LPSTR pcOut
);

パラメーター

名前方向
uiInSHORTin
pcOutLPSTRout

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT VarI1FromI2(
    SHORT uiIn,
    LPSTR pcOut
);
[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int VarI1FromI2(
    short uiIn,   // SHORT
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pcOut   // LPSTR out
);
<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function VarI1FromI2(
    uiIn As Short,   ' SHORT
    <MarshalAs(UnmanagedType.LPStr)> pcOut As System.Text.StringBuilder   ' LPSTR out
) As Integer
End Function
' uiIn : SHORT
' pcOut : LPSTR out
Declare PtrSafe Function VarI1FromI2 Lib "oleaut32" ( _
    ByVal uiIn As Integer, _
    ByVal pcOut As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

VarI1FromI2 = ctypes.windll.oleaut32.VarI1FromI2
VarI1FromI2.restype = ctypes.c_int
VarI1FromI2.argtypes = [
    ctypes.c_short,  # uiIn : SHORT
    wintypes.LPSTR,  # pcOut : LPSTR out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procVarI1FromI2 = oleaut32.NewProc("VarI1FromI2")
)

// uiIn (SHORT), pcOut (LPSTR out)
r1, _, err := procVarI1FromI2.Call(
	uintptr(uiIn),
	uintptr(pcOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function VarI1FromI2(
  uiIn: Smallint;   // SHORT
  pcOut: PAnsiChar   // LPSTR out
): Integer; stdcall;
  external 'OLEAUT32.dll' name 'VarI1FromI2';
result := DllCall("OLEAUT32\VarI1FromI2"
    , "Short", uiIn   ; SHORT
    , "Ptr", pcOut   ; LPSTR out
    , "Int")   ; return: HRESULT
●VarI1FromI2(uiIn, pcOut) = DLL("OLEAUT32.dll", "int VarI1FromI2(int, char*)")
# 呼び出し: VarI1FromI2(uiIn, pcOut)
# uiIn : SHORT -> "int"
# pcOut : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。