ホーム › System.DataExchange › GlobalFindAtomA
GlobalFindAtomA
関数指定文字列に対応するグローバルアトムを検索する(ANSI)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
WORD GlobalFindAtomA(
LPCSTR lpString // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpString | LPCSTR | inoptional | 検索対象となる、null で終端された文字列。 あるいは、MAKEINTATOM マクロで変換した整数アトムを使用することもできます。詳細は「解説」を参照してください。 |
戻り値の型: WORD
公式ドキュメント
グローバルアトムテーブルから指定した文字列を検索し、その文字列に関連付けられたグローバルアトムを取得します。(ANSI)
戻り値
型: ATOM
関数が成功した場合、戻り値は指定した文字列に関連付けられたグローバルアトムです。
関数が失敗した場合、戻り値はゼロです。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
システムはアトムテーブル内の文字列を最初に入力されたときの大文字小文字のまま保持しますが、GlobalFindAtom が行う検索では大文字小文字は区別されません。
lpString が MAKEINTATOM マクロで作成されたものである場合、下位ワードは 0x0001 から 0xBFFF の範囲内でなければなりません。下位ワードがこの範囲内にない場合、関数は失敗します。
メモ
winbase.h ヘッダーは GlobalFindAtom を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。このエンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
WORD GlobalFindAtomA(
LPCSTR lpString // optional
);[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern ushort GlobalFindAtomA(
[MarshalAs(UnmanagedType.LPStr)] string lpString // LPCSTR optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GlobalFindAtomA(
<MarshalAs(UnmanagedType.LPStr)> lpString As String ' LPCSTR optional
) As UShort
End Function' lpString : LPCSTR optional
Declare PtrSafe Function GlobalFindAtomA Lib "kernel32" ( _
ByVal lpString As String) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GlobalFindAtomA = ctypes.windll.kernel32.GlobalFindAtomA
GlobalFindAtomA.restype = ctypes.c_ushort
GlobalFindAtomA.argtypes = [
wintypes.LPCSTR, # lpString : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GlobalFindAtomA = Fiddle::Function.new(
lib['GlobalFindAtomA'],
[
Fiddle::TYPE_VOIDP, # lpString : LPCSTR optional
],
-Fiddle::TYPE_SHORT)#[link(name = "kernel32")]
extern "system" {
fn GlobalFindAtomA(
lpString: *const u8 // LPCSTR optional
) -> u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern ushort GlobalFindAtomA([MarshalAs(UnmanagedType.LPStr)] string lpString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GlobalFindAtomA' -Namespace Win32 -PassThru
# $api::GlobalFindAtomA(lpString)#uselib "KERNEL32.dll"
#func global GlobalFindAtomA "GlobalFindAtomA" sptr
; GlobalFindAtomA lpString ; 戻り値は stat
; lpString : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GlobalFindAtomA "GlobalFindAtomA" str
; res = GlobalFindAtomA(lpString)
; lpString : LPCSTR optional -> "str"; WORD GlobalFindAtomA(LPCSTR lpString)
#uselib "KERNEL32.dll"
#cfunc global GlobalFindAtomA "GlobalFindAtomA" str
; res = GlobalFindAtomA(lpString)
; lpString : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGlobalFindAtomA = kernel32.NewProc("GlobalFindAtomA")
)
// lpString (LPCSTR optional)
r1, _, err := procGlobalFindAtomA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpString))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WORDfunction GlobalFindAtomA(
lpString: PAnsiChar // LPCSTR optional
): Word; stdcall;
external 'KERNEL32.dll' name 'GlobalFindAtomA';result := DllCall("KERNEL32\GlobalFindAtomA"
, "AStr", lpString ; LPCSTR optional
, "UShort") ; return: WORD●GlobalFindAtomA(lpString) = DLL("KERNEL32.dll", "int GlobalFindAtomA(char*)")
# 呼び出し: GlobalFindAtomA(lpString)
# lpString : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn GlobalFindAtomA(
lpString: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u16;proc GlobalFindAtomA(
lpString: cstring # LPCSTR optional
): uint16 {.importc: "GlobalFindAtomA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
ushort GlobalFindAtomA(
const(char)* lpString // LPCSTR optional
);ccall((:GlobalFindAtomA, "KERNEL32.dll"), stdcall, UInt16,
(Cstring,),
lpString)
# lpString : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint16_t GlobalFindAtomA(
const char* lpString);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GlobalFindAtomA(lpString)
-- lpString : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GlobalFindAtomA = lib.func('__stdcall', 'GlobalFindAtomA', 'uint16_t', ['str']);
// GlobalFindAtomA(lpString)
// lpString : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GlobalFindAtomA: { parameters: ["buffer"], result: "u16" },
});
// lib.symbols.GlobalFindAtomA(lpString)
// lpString : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint16_t GlobalFindAtomA(
const char* lpString);
C, "KERNEL32.dll");
// $ffi->GlobalFindAtomA(lpString);
// lpString : LPCSTR optional
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.ASCII_OPTIONS);
short GlobalFindAtomA(
String lpString // LPCSTR optional
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GlobalFindAtomA = GlobalFindAtomA(
lpString : UInt8* # LPCSTR optional
) : UInt16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GlobalFindAtomANative = Uint16 Function(Pointer<Utf8>);
typedef GlobalFindAtomADart = int Function(Pointer<Utf8>);
final GlobalFindAtomA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GlobalFindAtomANative, GlobalFindAtomADart>('GlobalFindAtomA');
// lpString : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GlobalFindAtomA(
lpString: PAnsiChar // LPCSTR optional
): Word; stdcall;
external 'KERNEL32.dll' name 'GlobalFindAtomA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GlobalFindAtomA"
c_GlobalFindAtomA :: CString -> IO Word16
-- lpString : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let globalfindatoma =
foreign "GlobalFindAtomA"
(string @-> returning uint16_t)
(* lpString : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GlobalFindAtomA" global-find-atom-a :convention :stdcall) :uint16
(lp-string :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GlobalFindAtomA = Win32::API::More->new('KERNEL32',
'WORD GlobalFindAtomA(LPCSTR lpString)');
# my $ret = $GlobalFindAtomA->Call($lpString);
# lpString : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f GlobalFindAtomW (Unicode版) — 指定文字列に対応するグローバルアトムを検索する(Unicode)。
公式の関連項目
- f AddAtomA — 文字列をローカルアトムテーブルに追加しアトムを返す(ANSI)。
- f DeleteAtom — ローカルアトムテーブルのアトム参照カウントを減らし削除する。
- f FindAtomA — 指定文字列に対応するローカルアトムを検索する(ANSI)。
- f GetAtomNameA — ローカルアトムに関連付けられた文字列を取得する(ANSI)。
- f GlobalAddAtomA — 文字列をグローバルアトムテーブルに追加しアトムを返す(ANSI)。
- f GlobalDeleteAtom — グローバルアトムテーブルのアトム参照カウントを減らし削除する。
- f GlobalGetAtomNameA — グローバルアトムに関連付けられた文字列を取得する(ANSI)。