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

GlobalGetAtomNameA

関数
グローバルアトムに関連付けられた文字列を取得する(ANSI)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

DWORD GlobalGetAtomNameA(
    WORD nAtom,
    LPSTR lpBuffer,
    INT nSize
);

パラメーター

名前方向
nAtomWORDin
lpBufferLPSTRout
nSizeINTin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GlobalGetAtomNameA(
    WORD nAtom,
    LPSTR lpBuffer,
    INT nSize
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GlobalGetAtomNameA(
    ushort nAtom,   // WORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer,   // LPSTR out
    int nSize   // INT
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GlobalGetAtomNameA(
    nAtom As UShort,   ' WORD
    <MarshalAs(UnmanagedType.LPStr)> lpBuffer As System.Text.StringBuilder,   ' LPSTR out
    nSize As Integer   ' INT
) As UInteger
End Function
' nAtom : WORD
' lpBuffer : LPSTR out
' nSize : INT
Declare PtrSafe Function GlobalGetAtomNameA Lib "kernel32" ( _
    ByVal nAtom As Integer, _
    ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GlobalGetAtomNameA = ctypes.windll.kernel32.GlobalGetAtomNameA
GlobalGetAtomNameA.restype = wintypes.DWORD
GlobalGetAtomNameA.argtypes = [
    ctypes.c_ushort,  # nAtom : WORD
    wintypes.LPSTR,  # lpBuffer : LPSTR out
    ctypes.c_int,  # nSize : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGlobalGetAtomNameA = kernel32.NewProc("GlobalGetAtomNameA")
)

// nAtom (WORD), lpBuffer (LPSTR out), nSize (INT)
r1, _, err := procGlobalGetAtomNameA.Call(
	uintptr(nAtom),
	uintptr(lpBuffer),
	uintptr(nSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GlobalGetAtomNameA(
  nAtom: Word;   // WORD
  lpBuffer: PAnsiChar;   // LPSTR out
  nSize: Integer   // INT
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GlobalGetAtomNameA';
result := DllCall("KERNEL32\GlobalGetAtomNameA"
    , "UShort", nAtom   ; WORD
    , "Ptr", lpBuffer   ; LPSTR out
    , "Int", nSize   ; INT
    , "UInt")   ; return: DWORD
●GlobalGetAtomNameA(nAtom, lpBuffer, nSize) = DLL("KERNEL32.dll", "dword GlobalGetAtomNameA(int, char*, int)")
# 呼び出し: GlobalGetAtomNameA(nAtom, lpBuffer, nSize)
# nAtom : WORD -> "int"
# lpBuffer : LPSTR out -> "char*"
# nSize : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。