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

FindAtomA

関数
指定文字列に対応するローカルアトムを検索する(ANSI)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

WORD FindAtomA(
    LPCSTR lpString   // optional
);

パラメーター

名前方向説明
lpStringLPCSTRinoptional

検索する文字列。

代わりに、MAKEINTATOM マクロで変換した整数アトムを使用することもできます。詳細については「解説」を参照してください。

戻り値の型: WORD

公式ドキュメント

指定した文字列をローカルアトムテーブルから検索し、その文字列に関連付けられたアトムを取得します。(ANSI)

戻り値

型: ATOM

関数が成功した場合、戻り値は指定した文字列に関連付けられたアトムです。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

システムはアトムテーブル内の文字列の大文字小文字を保持しますが、FindAtom 関数による検索では大文字と小文字は区別されません。

lpStringMAKEINTATOM マクロで作成された場合、下位ワードは 0x0001 から 0xBFFF までの範囲内でなければなりません。下位ワードがこの範囲外の場合、関数は失敗します。

メモ

winbase.h ヘッダーは FindAtom をエイリアスとして定義しており、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)

各言語での呼び出し定義

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

WORD FindAtomA(
    LPCSTR lpString   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern ushort FindAtomA(
    [MarshalAs(UnmanagedType.LPStr)] string lpString   // LPCSTR optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindAtomA(
    <MarshalAs(UnmanagedType.LPStr)> lpString As String   ' LPCSTR optional
) As UShort
End Function
' lpString : LPCSTR optional
Declare PtrSafe Function FindAtomA 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

FindAtomA = ctypes.windll.kernel32.FindAtomA
FindAtomA.restype = ctypes.c_ushort
FindAtomA.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')
FindAtomA = Fiddle::Function.new(
  lib['FindAtomA'],
  [
    Fiddle::TYPE_VOIDP,  # lpString : LPCSTR optional
  ],
  -Fiddle::TYPE_SHORT)
#[link(name = "kernel32")]
extern "system" {
    fn FindAtomA(
        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 FindAtomA([MarshalAs(UnmanagedType.LPStr)] string lpString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindAtomA' -Namespace Win32 -PassThru
# $api::FindAtomA(lpString)
#uselib "KERNEL32.dll"
#func global FindAtomA "FindAtomA" sptr
; FindAtomA lpString   ; 戻り値は stat
; lpString : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global FindAtomA "FindAtomA" str
; res = FindAtomA(lpString)
; lpString : LPCSTR optional -> "str"
; WORD FindAtomA(LPCSTR lpString)
#uselib "KERNEL32.dll"
#cfunc global FindAtomA "FindAtomA" str
; res = FindAtomA(lpString)
; lpString : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindAtomA = kernel32.NewProc("FindAtomA")
)

// lpString (LPCSTR optional)
r1, _, err := procFindAtomA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpString))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WORD
function FindAtomA(
  lpString: PAnsiChar   // LPCSTR optional
): Word; stdcall;
  external 'KERNEL32.dll' name 'FindAtomA';
result := DllCall("KERNEL32\FindAtomA"
    , "AStr", lpString   ; LPCSTR optional
    , "UShort")   ; return: WORD
●FindAtomA(lpString) = DLL("KERNEL32.dll", "int FindAtomA(char*)")
# 呼び出し: FindAtomA(lpString)
# lpString : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn FindAtomA(
    lpString: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u16;
proc FindAtomA(
    lpString: cstring  # LPCSTR optional
): uint16 {.importc: "FindAtomA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
ushort FindAtomA(
    const(char)* lpString   // LPCSTR optional
);
ccall((:FindAtomA, "KERNEL32.dll"), stdcall, UInt16,
      (Cstring,),
      lpString)
# lpString : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint16_t FindAtomA(
    const char* lpString);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.FindAtomA(lpString)
-- lpString : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const FindAtomA = lib.func('__stdcall', 'FindAtomA', 'uint16_t', ['str']);
// FindAtomA(lpString)
// lpString : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  FindAtomA: { parameters: ["buffer"], result: "u16" },
});
// lib.symbols.FindAtomA(lpString)
// lpString : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint16_t FindAtomA(
    const char* lpString);
C, "KERNEL32.dll");
// $ffi->FindAtomA(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 FindAtomA(
        String lpString   // LPCSTR optional
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun FindAtomA = FindAtomA(
    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 FindAtomANative = Uint16 Function(Pointer<Utf8>);
typedef FindAtomADart = int Function(Pointer<Utf8>);
final FindAtomA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<FindAtomANative, FindAtomADart>('FindAtomA');
// lpString : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FindAtomA(
  lpString: PAnsiChar   // LPCSTR optional
): Word; stdcall;
  external 'KERNEL32.dll' name 'FindAtomA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "FindAtomA"
  c_FindAtomA :: CString -> IO Word16
-- lpString : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let findatoma =
  foreign "FindAtomA"
    (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 ("FindAtomA" 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 $FindAtomA = Win32::API::More->new('KERNEL32',
    'WORD FindAtomA(LPCSTR lpString)');
# my $ret = $FindAtomA->Call($lpString);
# lpString : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目