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

GetRoleTextA

関数
アクセシビリティのロールIDの説明文字列(ANSI)を取得する。
DLLOLEACC.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// OLEACC.dll  (ANSI / -A)
#include <windows.h>

DWORD GetRoleTextA(
    DWORD lRole,
    LPSTR lpszRole,   // optional
    DWORD cchRoleMax
);

パラメーター

名前方向
lRoleDWORDin
lpszRoleLPSTRoutoptional
cchRoleMaxDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// OLEACC.dll  (ANSI / -A)
#include <windows.h>

DWORD GetRoleTextA(
    DWORD lRole,
    LPSTR lpszRole,   // optional
    DWORD cchRoleMax
);
[DllImport("OLEACC.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetRoleTextA(
    uint lRole,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszRole,   // LPSTR optional, out
    uint cchRoleMax   // DWORD
);
<DllImport("OLEACC.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetRoleTextA(
    lRole As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpszRole As System.Text.StringBuilder,   ' LPSTR optional, out
    cchRoleMax As UInteger   ' DWORD
) As UInteger
End Function
' lRole : DWORD
' lpszRole : LPSTR optional, out
' cchRoleMax : DWORD
Declare PtrSafe Function GetRoleTextA Lib "oleacc" ( _
    ByVal lRole As Long, _
    ByVal lpszRole As String, _
    ByVal cchRoleMax As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetRoleTextA = ctypes.windll.oleacc.GetRoleTextA
GetRoleTextA.restype = wintypes.DWORD
GetRoleTextA.argtypes = [
    wintypes.DWORD,  # lRole : DWORD
    wintypes.LPSTR,  # lpszRole : LPSTR optional, out
    wintypes.DWORD,  # cchRoleMax : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	oleacc = windows.NewLazySystemDLL("OLEACC.dll")
	procGetRoleTextA = oleacc.NewProc("GetRoleTextA")
)

// lRole (DWORD), lpszRole (LPSTR optional, out), cchRoleMax (DWORD)
r1, _, err := procGetRoleTextA.Call(
	uintptr(lRole),
	uintptr(lpszRole),
	uintptr(cchRoleMax),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetRoleTextA(
  lRole: DWORD;   // DWORD
  lpszRole: PAnsiChar;   // LPSTR optional, out
  cchRoleMax: DWORD   // DWORD
): DWORD; stdcall;
  external 'OLEACC.dll' name 'GetRoleTextA';
result := DllCall("OLEACC\GetRoleTextA"
    , "UInt", lRole   ; DWORD
    , "Ptr", lpszRole   ; LPSTR optional, out
    , "UInt", cchRoleMax   ; DWORD
    , "UInt")   ; return: DWORD
●GetRoleTextA(lRole, lpszRole, cchRoleMax) = DLL("OLEACC.dll", "dword GetRoleTextA(dword, char*, dword)")
# 呼び出し: GetRoleTextA(lRole, lpszRole, cchRoleMax)
# lRole : DWORD -> "dword"
# lpszRole : LPSTR optional, out -> "char*"
# cchRoleMax : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。