Win32 API 日本語リファレンス
ホームUI.Accessibility › TextRange_MoveEndpointByUnit

TextRange_MoveEndpointByUnit

関数
テキスト範囲の端点を指定単位ぶん移動する。
DLLUIAutomationCore.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT TextRange_MoveEndpointByUnit(
    HUIATEXTRANGE hobj,
    TextPatternRangeEndpoint endpoint,
    TextUnit unit,
    INT count,
    INT* pRetVal
);

パラメーター

名前方向説明
hobjHUIATEXTRANGEin移動対象のテキスト範囲ハンドル。
endpointTextPatternRangeEndpointin移動させる端点(始点・終点)を示すTextPatternRangeEndpoint値。
unitTextUnitin移動の単位(文字・単語・行など)を示すTextUnit値。
countINTin移動する単位数。負値で後方へ移動する。
pRetValINT*inout実際に移動できた単位数を受け取る出力先。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT TextRange_MoveEndpointByUnit(
    HUIATEXTRANGE hobj,
    TextPatternRangeEndpoint endpoint,
    TextUnit unit,
    INT count,
    INT* pRetVal
);
[DllImport("UIAutomationCore.dll", ExactSpelling = true)]
static extern int TextRange_MoveEndpointByUnit(
    IntPtr hobj,   // HUIATEXTRANGE
    int endpoint,   // TextPatternRangeEndpoint
    int unit,   // TextUnit
    int count,   // INT
    ref int pRetVal   // INT* in/out
);
<DllImport("UIAutomationCore.dll", ExactSpelling:=True)>
Public Shared Function TextRange_MoveEndpointByUnit(
    hobj As IntPtr,   ' HUIATEXTRANGE
    endpoint As Integer,   ' TextPatternRangeEndpoint
    unit As Integer,   ' TextUnit
    count As Integer,   ' INT
    ByRef pRetVal As Integer   ' INT* in/out
) As Integer
End Function
' hobj : HUIATEXTRANGE
' endpoint : TextPatternRangeEndpoint
' unit : TextUnit
' count : INT
' pRetVal : INT* in/out
Declare PtrSafe Function TextRange_MoveEndpointByUnit Lib "uiautomationcore" ( _
    ByVal hobj As LongPtr, _
    ByVal endpoint As Long, _
    ByVal unit As Long, _
    ByVal count As Long, _
    ByRef pRetVal As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TextRange_MoveEndpointByUnit = ctypes.windll.uiautomationcore.TextRange_MoveEndpointByUnit
TextRange_MoveEndpointByUnit.restype = ctypes.c_int
TextRange_MoveEndpointByUnit.argtypes = [
    wintypes.HANDLE,  # hobj : HUIATEXTRANGE
    ctypes.c_int,  # endpoint : TextPatternRangeEndpoint
    ctypes.c_int,  # unit : TextUnit
    ctypes.c_int,  # count : INT
    ctypes.POINTER(ctypes.c_int),  # pRetVal : INT* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UIAutomationCore.dll')
TextRange_MoveEndpointByUnit = Fiddle::Function.new(
  lib['TextRange_MoveEndpointByUnit'],
  [
    Fiddle::TYPE_VOIDP,  # hobj : HUIATEXTRANGE
    Fiddle::TYPE_INT,  # endpoint : TextPatternRangeEndpoint
    Fiddle::TYPE_INT,  # unit : TextUnit
    Fiddle::TYPE_INT,  # count : INT
    Fiddle::TYPE_VOIDP,  # pRetVal : INT* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "uiautomationcore")]
extern "system" {
    fn TextRange_MoveEndpointByUnit(
        hobj: *mut core::ffi::c_void,  // HUIATEXTRANGE
        endpoint: i32,  // TextPatternRangeEndpoint
        unit: i32,  // TextUnit
        count: i32,  // INT
        pRetVal: *mut i32  // INT* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UIAutomationCore.dll")]
public static extern int TextRange_MoveEndpointByUnit(IntPtr hobj, int endpoint, int unit, int count, ref int pRetVal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UIAutomationCore_TextRange_MoveEndpointByUnit' -Namespace Win32 -PassThru
# $api::TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
#uselib "UIAutomationCore.dll"
#func global TextRange_MoveEndpointByUnit "TextRange_MoveEndpointByUnit" sptr, sptr, sptr, sptr, sptr
; TextRange_MoveEndpointByUnit hobj, endpoint, unit, count, varptr(pRetVal)   ; 戻り値は stat
; hobj : HUIATEXTRANGE -> "sptr"
; endpoint : TextPatternRangeEndpoint -> "sptr"
; unit : TextUnit -> "sptr"
; count : INT -> "sptr"
; pRetVal : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UIAutomationCore.dll"
#cfunc global TextRange_MoveEndpointByUnit "TextRange_MoveEndpointByUnit" sptr, int, int, int, var
; res = TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
; hobj : HUIATEXTRANGE -> "sptr"
; endpoint : TextPatternRangeEndpoint -> "int"
; unit : TextUnit -> "int"
; count : INT -> "int"
; pRetVal : INT* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT TextRange_MoveEndpointByUnit(HUIATEXTRANGE hobj, TextPatternRangeEndpoint endpoint, TextUnit unit, INT count, INT* pRetVal)
#uselib "UIAutomationCore.dll"
#cfunc global TextRange_MoveEndpointByUnit "TextRange_MoveEndpointByUnit" intptr, int, int, int, var
; res = TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
; hobj : HUIATEXTRANGE -> "intptr"
; endpoint : TextPatternRangeEndpoint -> "int"
; unit : TextUnit -> "int"
; count : INT -> "int"
; pRetVal : INT* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uiautomationcore = windows.NewLazySystemDLL("UIAutomationCore.dll")
	procTextRange_MoveEndpointByUnit = uiautomationcore.NewProc("TextRange_MoveEndpointByUnit")
)

// hobj (HUIATEXTRANGE), endpoint (TextPatternRangeEndpoint), unit (TextUnit), count (INT), pRetVal (INT* in/out)
r1, _, err := procTextRange_MoveEndpointByUnit.Call(
	uintptr(hobj),
	uintptr(endpoint),
	uintptr(unit),
	uintptr(count),
	uintptr(pRetVal),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function TextRange_MoveEndpointByUnit(
  hobj: THandle;   // HUIATEXTRANGE
  endpoint: Integer;   // TextPatternRangeEndpoint
  unit: Integer;   // TextUnit
  count: Integer;   // INT
  pRetVal: Pointer   // INT* in/out
): Integer; stdcall;
  external 'UIAutomationCore.dll' name 'TextRange_MoveEndpointByUnit';
result := DllCall("UIAutomationCore\TextRange_MoveEndpointByUnit"
    , "Ptr", hobj   ; HUIATEXTRANGE
    , "Int", endpoint   ; TextPatternRangeEndpoint
    , "Int", unit   ; TextUnit
    , "Int", count   ; INT
    , "Ptr", pRetVal   ; INT* in/out
    , "Int")   ; return: HRESULT
●TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal) = DLL("UIAutomationCore.dll", "int TextRange_MoveEndpointByUnit(void*, int, int, int, void*)")
# 呼び出し: TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
# hobj : HUIATEXTRANGE -> "void*"
# endpoint : TextPatternRangeEndpoint -> "int"
# unit : TextUnit -> "int"
# count : INT -> "int"
# pRetVal : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "uiautomationcore" fn TextRange_MoveEndpointByUnit(
    hobj: ?*anyopaque, // HUIATEXTRANGE
    endpoint: i32, // TextPatternRangeEndpoint
    unit: i32, // TextUnit
    count: i32, // INT
    pRetVal: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i32;
proc TextRange_MoveEndpointByUnit(
    hobj: pointer,  # HUIATEXTRANGE
    endpoint: int32,  # TextPatternRangeEndpoint
    unit: int32,  # TextUnit
    count: int32,  # INT
    pRetVal: ptr int32  # INT* in/out
): int32 {.importc: "TextRange_MoveEndpointByUnit", stdcall, dynlib: "UIAutomationCore.dll".}
pragma(lib, "uiautomationcore");
extern(Windows)
int TextRange_MoveEndpointByUnit(
    void* hobj,   // HUIATEXTRANGE
    int endpoint,   // TextPatternRangeEndpoint
    int unit,   // TextUnit
    int count,   // INT
    int* pRetVal   // INT* in/out
);
ccall((:TextRange_MoveEndpointByUnit, "UIAutomationCore.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Int32, Int32, Ptr{Int32}),
      hobj, endpoint, unit, count, pRetVal)
# hobj : HUIATEXTRANGE -> Ptr{Cvoid}
# endpoint : TextPatternRangeEndpoint -> Int32
# unit : TextUnit -> Int32
# count : INT -> Int32
# pRetVal : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t TextRange_MoveEndpointByUnit(
    void* hobj,
    int32_t endpoint,
    int32_t unit,
    int32_t count,
    int32_t* pRetVal);
]]
local uiautomationcore = ffi.load("uiautomationcore")
-- uiautomationcore.TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
-- hobj : HUIATEXTRANGE
-- endpoint : TextPatternRangeEndpoint
-- unit : TextUnit
-- count : INT
-- pRetVal : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UIAutomationCore.dll');
const TextRange_MoveEndpointByUnit = lib.func('__stdcall', 'TextRange_MoveEndpointByUnit', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t *']);
// TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
// hobj : HUIATEXTRANGE -> 'void *'
// endpoint : TextPatternRangeEndpoint -> 'int32_t'
// unit : TextUnit -> 'int32_t'
// count : INT -> 'int32_t'
// pRetVal : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UIAutomationCore.dll", {
  TextRange_MoveEndpointByUnit: { parameters: ["pointer", "i32", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal)
// hobj : HUIATEXTRANGE -> "pointer"
// endpoint : TextPatternRangeEndpoint -> "i32"
// unit : TextUnit -> "i32"
// count : INT -> "i32"
// pRetVal : INT* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t TextRange_MoveEndpointByUnit(
    void* hobj,
    int32_t endpoint,
    int32_t unit,
    int32_t count,
    int32_t* pRetVal);
C, "UIAutomationCore.dll");
// $ffi->TextRange_MoveEndpointByUnit(hobj, endpoint, unit, count, pRetVal);
// hobj : HUIATEXTRANGE
// endpoint : TextPatternRangeEndpoint
// unit : TextUnit
// count : INT
// pRetVal : INT* in/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 Uiautomationcore extends StdCallLibrary {
    Uiautomationcore INSTANCE = Native.load("uiautomationcore", Uiautomationcore.class);
    int TextRange_MoveEndpointByUnit(
        Pointer hobj,   // HUIATEXTRANGE
        int endpoint,   // TextPatternRangeEndpoint
        int unit,   // TextUnit
        int count,   // INT
        IntByReference pRetVal   // INT* in/out
    );
}
@[Link("uiautomationcore")]
lib LibUIAutomationCore
  fun TextRange_MoveEndpointByUnit = TextRange_MoveEndpointByUnit(
    hobj : Void*,   # HUIATEXTRANGE
    endpoint : Int32,   # TextPatternRangeEndpoint
    unit : Int32,   # TextUnit
    count : Int32,   # INT
    pRetVal : Int32*   # INT* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef TextRange_MoveEndpointByUnitNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Pointer<Int32>);
typedef TextRange_MoveEndpointByUnitDart = int Function(Pointer<Void>, int, int, int, Pointer<Int32>);
final TextRange_MoveEndpointByUnit = DynamicLibrary.open('UIAutomationCore.dll')
    .lookupFunction<TextRange_MoveEndpointByUnitNative, TextRange_MoveEndpointByUnitDart>('TextRange_MoveEndpointByUnit');
// hobj : HUIATEXTRANGE -> Pointer<Void>
// endpoint : TextPatternRangeEndpoint -> Int32
// unit : TextUnit -> Int32
// count : INT -> Int32
// pRetVal : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TextRange_MoveEndpointByUnit(
  hobj: THandle;   // HUIATEXTRANGE
  endpoint: Integer;   // TextPatternRangeEndpoint
  unit: Integer;   // TextUnit
  count: Integer;   // INT
  pRetVal: Pointer   // INT* in/out
): Integer; stdcall;
  external 'UIAutomationCore.dll' name 'TextRange_MoveEndpointByUnit';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TextRange_MoveEndpointByUnit"
  c_TextRange_MoveEndpointByUnit :: Ptr () -> Int32 -> Int32 -> Int32 -> Ptr Int32 -> IO Int32
-- hobj : HUIATEXTRANGE -> Ptr ()
-- endpoint : TextPatternRangeEndpoint -> Int32
-- unit : TextUnit -> Int32
-- count : INT -> Int32
-- pRetVal : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let textrange_moveendpointbyunit =
  foreign "TextRange_MoveEndpointByUnit"
    ((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* hobj : HUIATEXTRANGE -> (ptr void) *)
(* endpoint : TextPatternRangeEndpoint -> int32_t *)
(* unit : TextUnit -> int32_t *)
(* count : INT -> int32_t *)
(* pRetVal : INT* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uiautomationcore (t "UIAutomationCore.dll"))
(cffi:use-foreign-library uiautomationcore)

(cffi:defcfun ("TextRange_MoveEndpointByUnit" text-range-move-endpoint-by-unit :convention :stdcall) :int32
  (hobj :pointer)   ; HUIATEXTRANGE
  (endpoint :int32)   ; TextPatternRangeEndpoint
  (unit :int32)   ; TextUnit
  (count :int32)   ; INT
  (p-ret-val :pointer))   ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TextRange_MoveEndpointByUnit = Win32::API::More->new('UIAutomationCore',
    'int TextRange_MoveEndpointByUnit(HANDLE hobj, int endpoint, int unit, int count, LPVOID pRetVal)');
# my $ret = $TextRange_MoveEndpointByUnit->Call($hobj, $endpoint, $unit, $count, $pRetVal);
# hobj : HUIATEXTRANGE -> HANDLE
# endpoint : TextPatternRangeEndpoint -> int
# unit : TextUnit -> int
# count : INT -> int
# pRetVal : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型