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テキストを取得するロール識別子(ROLE_SYSTEM_*)。
lpszRoleLPSTRoutoptional出力としてロール説明文字列を受け取るバッファ(ANSI)。NULLで必要長取得。
cchRoleMaxDWORDinlpszRoleバッファの文字数(NUL終端含む)。

戻り値の型: 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)。
const std = @import("std");

extern "oleacc" fn GetRoleTextA(
    lRole: u32, // DWORD
    lpszRole: [*c]u8, // LPSTR optional, out
    cchRoleMax: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc GetRoleTextA(
    lRole: uint32,  # DWORD
    lpszRole: ptr char,  # LPSTR optional, out
    cchRoleMax: uint32  # DWORD
): uint32 {.importc: "GetRoleTextA", stdcall, dynlib: "OLEACC.dll".}
pragma(lib, "oleacc");
extern(Windows)
uint GetRoleTextA(
    uint lRole,   // DWORD
    char* lpszRole,   // LPSTR optional, out
    uint cchRoleMax   // DWORD
);
ccall((:GetRoleTextA, "OLEACC.dll"), stdcall, UInt32,
      (UInt32, Ptr{UInt8}, UInt32),
      lRole, lpszRole, cchRoleMax)
# lRole : DWORD -> UInt32
# lpszRole : LPSTR optional, out -> Ptr{UInt8}
# cchRoleMax : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetRoleTextA(
    uint32_t lRole,
    char* lpszRole,
    uint32_t cchRoleMax);
]]
local oleacc = ffi.load("oleacc")
-- oleacc.GetRoleTextA(lRole, lpszRole, cchRoleMax)
-- lRole : DWORD
-- lpszRole : LPSTR optional, out
-- cchRoleMax : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('OLEACC.dll');
const GetRoleTextA = lib.func('__stdcall', 'GetRoleTextA', 'uint32_t', ['uint32_t', 'char *', 'uint32_t']);
// GetRoleTextA(lRole, lpszRole, cchRoleMax)
// lRole : DWORD -> 'uint32_t'
// lpszRole : LPSTR optional, out -> 'char *'
// cchRoleMax : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("OLEACC.dll", {
  GetRoleTextA: { parameters: ["u32", "buffer", "u32"], result: "u32" },
});
// lib.symbols.GetRoleTextA(lRole, lpszRole, cchRoleMax)
// lRole : DWORD -> "u32"
// lpszRole : LPSTR optional, out -> "buffer"
// cchRoleMax : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetRoleTextA(
    uint32_t lRole,
    char* lpszRole,
    uint32_t cchRoleMax);
C, "OLEACC.dll");
// $ffi->GetRoleTextA(lRole, lpszRole, cchRoleMax);
// lRole : DWORD
// lpszRole : LPSTR optional, out
// cchRoleMax : DWORD
// 構造体/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 Oleacc extends StdCallLibrary {
    Oleacc INSTANCE = Native.load("oleacc", Oleacc.class, W32APIOptions.ASCII_OPTIONS);
    int GetRoleTextA(
        int lRole,   // DWORD
        byte[] lpszRole,   // LPSTR optional, out
        int cchRoleMax   // DWORD
    );
}
@[Link("oleacc")]
lib LibOLEACC
  fun GetRoleTextA = GetRoleTextA(
    lRole : UInt32,   # DWORD
    lpszRole : UInt8*,   # LPSTR optional, out
    cchRoleMax : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetRoleTextANative = Uint32 Function(Uint32, Pointer<Utf8>, Uint32);
typedef GetRoleTextADart = int Function(int, Pointer<Utf8>, int);
final GetRoleTextA = DynamicLibrary.open('OLEACC.dll')
    .lookupFunction<GetRoleTextANative, GetRoleTextADart>('GetRoleTextA');
// lRole : DWORD -> Uint32
// lpszRole : LPSTR optional, out -> Pointer<Utf8>
// cchRoleMax : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetRoleTextA(
  lRole: DWORD;   // DWORD
  lpszRole: PAnsiChar;   // LPSTR optional, out
  cchRoleMax: DWORD   // DWORD
): DWORD; stdcall;
  external 'OLEACC.dll' name 'GetRoleTextA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetRoleTextA"
  c_GetRoleTextA :: Word32 -> CString -> Word32 -> IO Word32
-- lRole : DWORD -> Word32
-- lpszRole : LPSTR optional, out -> CString
-- cchRoleMax : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getroletexta =
  foreign "GetRoleTextA"
    (uint32_t @-> string @-> uint32_t @-> returning uint32_t)
(* lRole : DWORD -> uint32_t *)
(* lpszRole : LPSTR optional, out -> string *)
(* cchRoleMax : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library oleacc (t "OLEACC.dll"))
(cffi:use-foreign-library oleacc)

(cffi:defcfun ("GetRoleTextA" get-role-text-a :convention :stdcall) :uint32
  (l-role :uint32)   ; DWORD
  (lpsz-role :pointer)   ; LPSTR optional, out
  (cch-role-max :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetRoleTextA = Win32::API::More->new('OLEACC',
    'DWORD GetRoleTextA(DWORD lRole, LPSTR lpszRole, DWORD cchRoleMax)');
# my $ret = $GetRoleTextA->Call($lRole, $lpszRole, $cchRoleMax);
# lRole : DWORD -> DWORD
# lpszRole : LPSTR optional, out -> LPSTR
# cchRoleMax : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い