ホーム › System.DataExchange › GlobalGetAtomNameW
GlobalGetAtomNameW
関数グローバルアトムに関連付けられた文字列を取得する(Unicode)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD GlobalGetAtomNameW(
WORD nAtom,
LPWSTR lpBuffer,
INT nSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| nAtom | WORD | in |
| lpBuffer | LPWSTR | out |
| nSize | INT | in |
戻り値の型: DWORD
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
DWORD GlobalGetAtomNameW(
WORD nAtom,
LPWSTR lpBuffer,
INT nSize
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint GlobalGetAtomNameW(
ushort nAtom, // WORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuffer, // LPWSTR out
int nSize // INT
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GlobalGetAtomNameW(
nAtom As UShort, ' WORD
<MarshalAs(UnmanagedType.LPWStr)> lpBuffer As System.Text.StringBuilder, ' LPWSTR out
nSize As Integer ' INT
) As UInteger
End Function' nAtom : WORD
' lpBuffer : LPWSTR out
' nSize : INT
Declare PtrSafe Function GlobalGetAtomNameW Lib "kernel32" ( _
ByVal nAtom As Integer, _
ByVal lpBuffer As LongPtr, _
ByVal nSize As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GlobalGetAtomNameW = ctypes.windll.kernel32.GlobalGetAtomNameW
GlobalGetAtomNameW.restype = wintypes.DWORD
GlobalGetAtomNameW.argtypes = [
ctypes.c_ushort, # nAtom : WORD
wintypes.LPWSTR, # lpBuffer : LPWSTR 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')
GlobalGetAtomNameW = Fiddle::Function.new(
lib['GlobalGetAtomNameW'],
[
-Fiddle::TYPE_SHORT, # nAtom : WORD
Fiddle::TYPE_VOIDP, # lpBuffer : LPWSTR out
Fiddle::TYPE_INT, # nSize : INT
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GlobalGetAtomNameW(
nAtom: u16, // WORD
lpBuffer: *mut u16, // LPWSTR out
nSize: i32 // INT
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint GlobalGetAtomNameW(ushort nAtom, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuffer, int nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GlobalGetAtomNameW' -Namespace Win32 -PassThru
# $api::GlobalGetAtomNameW(nAtom, lpBuffer, nSize)#uselib "KERNEL32.dll"
#func global GlobalGetAtomNameW "GlobalGetAtomNameW" wptr, wptr, wptr
; GlobalGetAtomNameW nAtom, varptr(lpBuffer), nSize ; 戻り値は stat
; nAtom : WORD -> "wptr"
; lpBuffer : LPWSTR out -> "wptr"
; nSize : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GlobalGetAtomNameW "GlobalGetAtomNameW" int, var, int ; res = GlobalGetAtomNameW(nAtom, lpBuffer, nSize) ; nAtom : WORD -> "int" ; lpBuffer : LPWSTR out -> "var" ; nSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GlobalGetAtomNameW "GlobalGetAtomNameW" int, sptr, int ; res = GlobalGetAtomNameW(nAtom, varptr(lpBuffer), nSize) ; nAtom : WORD -> "int" ; lpBuffer : LPWSTR out -> "sptr" ; nSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GlobalGetAtomNameW(WORD nAtom, LPWSTR lpBuffer, INT nSize) #uselib "KERNEL32.dll" #cfunc global GlobalGetAtomNameW "GlobalGetAtomNameW" int, var, int ; res = GlobalGetAtomNameW(nAtom, lpBuffer, nSize) ; nAtom : WORD -> "int" ; lpBuffer : LPWSTR out -> "var" ; nSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GlobalGetAtomNameW(WORD nAtom, LPWSTR lpBuffer, INT nSize) #uselib "KERNEL32.dll" #cfunc global GlobalGetAtomNameW "GlobalGetAtomNameW" int, intptr, int ; res = GlobalGetAtomNameW(nAtom, varptr(lpBuffer), nSize) ; nAtom : WORD -> "int" ; lpBuffer : LPWSTR out -> "intptr" ; nSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGlobalGetAtomNameW = kernel32.NewProc("GlobalGetAtomNameW")
)
// nAtom (WORD), lpBuffer (LPWSTR out), nSize (INT)
r1, _, err := procGlobalGetAtomNameW.Call(
uintptr(nAtom),
uintptr(lpBuffer),
uintptr(nSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GlobalGetAtomNameW(
nAtom: Word; // WORD
lpBuffer: PWideChar; // LPWSTR out
nSize: Integer // INT
): DWORD; stdcall;
external 'KERNEL32.dll' name 'GlobalGetAtomNameW';result := DllCall("KERNEL32\GlobalGetAtomNameW"
, "UShort", nAtom ; WORD
, "Ptr", lpBuffer ; LPWSTR out
, "Int", nSize ; INT
, "UInt") ; return: DWORD●GlobalGetAtomNameW(nAtom, lpBuffer, nSize) = DLL("KERNEL32.dll", "dword GlobalGetAtomNameW(int, char*, int)")
# 呼び出し: GlobalGetAtomNameW(nAtom, lpBuffer, nSize)
# nAtom : WORD -> "int"
# lpBuffer : LPWSTR out -> "char*"
# nSize : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。