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

TextPattern_GetSelection

関数
Textパターンで現在選択中のテキスト範囲を取得する。
DLLUIAutomationCore.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT TextPattern_GetSelection(
    HUIAPATTERNOBJECT hobj,
    SAFEARRAY** pRetVal
);

パラメーター

名前方向説明
hobjHUIAPATTERNOBJECTinTextPatternを表すパターンオブジェクトハンドル。
pRetValSAFEARRAY**inout現在の選択範囲を表すテキスト範囲ハンドルの配列(SAFEARRAY)を受け取る出力先。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

TextPattern_GetSelection = ctypes.windll.uiautomationcore.TextPattern_GetSelection
TextPattern_GetSelection.restype = ctypes.c_int
TextPattern_GetSelection.argtypes = [
    wintypes.HANDLE,  # hobj : HUIAPATTERNOBJECT
    ctypes.c_void_p,  # pRetVal : SAFEARRAY** in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	uiautomationcore = windows.NewLazySystemDLL("UIAutomationCore.dll")
	procTextPattern_GetSelection = uiautomationcore.NewProc("TextPattern_GetSelection")
)

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

extern "uiautomationcore" fn TextPattern_GetSelection(
    hobj: ?*anyopaque, // HUIAPATTERNOBJECT
    pRetVal: [*c][*c]SAFEARRAY // SAFEARRAY** in/out
) callconv(std.os.windows.WINAPI) i32;
proc TextPattern_GetSelection(
    hobj: pointer,  # HUIAPATTERNOBJECT
    pRetVal: ptr SAFEARRAY  # SAFEARRAY** in/out
): int32 {.importc: "TextPattern_GetSelection", stdcall, dynlib: "UIAutomationCore.dll".}
pragma(lib, "uiautomationcore");
extern(Windows)
int TextPattern_GetSelection(
    void* hobj,   // HUIAPATTERNOBJECT
    SAFEARRAY** pRetVal   // SAFEARRAY** in/out
);
ccall((:TextPattern_GetSelection, "UIAutomationCore.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{SAFEARRAY}),
      hobj, pRetVal)
# hobj : HUIAPATTERNOBJECT -> Ptr{Cvoid}
# pRetVal : SAFEARRAY** in/out -> Ptr{SAFEARRAY}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t TextPattern_GetSelection(
    void* hobj,
    void* pRetVal);
]]
local uiautomationcore = ffi.load("uiautomationcore")
-- uiautomationcore.TextPattern_GetSelection(hobj, pRetVal)
-- hobj : HUIAPATTERNOBJECT
-- pRetVal : SAFEARRAY** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UIAutomationCore.dll');
const TextPattern_GetSelection = lib.func('__stdcall', 'TextPattern_GetSelection', 'int32_t', ['void *', 'void *']);
// TextPattern_GetSelection(hobj, pRetVal)
// hobj : HUIAPATTERNOBJECT -> 'void *'
// pRetVal : SAFEARRAY** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UIAutomationCore.dll", {
  TextPattern_GetSelection: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.TextPattern_GetSelection(hobj, pRetVal)
// hobj : HUIAPATTERNOBJECT -> "pointer"
// pRetVal : SAFEARRAY** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t TextPattern_GetSelection(
    void* hobj,
    void* pRetVal);
C, "UIAutomationCore.dll");
// $ffi->TextPattern_GetSelection(hobj, pRetVal);
// hobj : HUIAPATTERNOBJECT
// pRetVal : SAFEARRAY** 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 TextPattern_GetSelection(
        Pointer hobj,   // HUIAPATTERNOBJECT
        Pointer pRetVal   // SAFEARRAY** in/out
    );
}
@[Link("uiautomationcore")]
lib LibUIAutomationCore
  fun TextPattern_GetSelection = TextPattern_GetSelection(
    hobj : Void*,   # HUIAPATTERNOBJECT
    pRetVal : SAFEARRAY**   # SAFEARRAY** 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 TextPattern_GetSelectionNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef TextPattern_GetSelectionDart = int Function(Pointer<Void>, Pointer<Void>);
final TextPattern_GetSelection = DynamicLibrary.open('UIAutomationCore.dll')
    .lookupFunction<TextPattern_GetSelectionNative, TextPattern_GetSelectionDart>('TextPattern_GetSelection');
// hobj : HUIAPATTERNOBJECT -> Pointer<Void>
// pRetVal : SAFEARRAY** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TextPattern_GetSelection(
  hobj: THandle;   // HUIAPATTERNOBJECT
  pRetVal: Pointer   // SAFEARRAY** in/out
): Integer; stdcall;
  external 'UIAutomationCore.dll' name 'TextPattern_GetSelection';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TextPattern_GetSelection"
  c_TextPattern_GetSelection :: Ptr () -> Ptr () -> IO Int32
-- hobj : HUIAPATTERNOBJECT -> Ptr ()
-- pRetVal : SAFEARRAY** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let textpattern_getselection =
  foreign "TextPattern_GetSelection"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* hobj : HUIAPATTERNOBJECT -> (ptr void) *)
(* pRetVal : SAFEARRAY** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uiautomationcore (t "UIAutomationCore.dll"))
(cffi:use-foreign-library uiautomationcore)

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

関連項目

使用する型