ホーム › System.DataExchange › RegisterClipboardFormatA
RegisterClipboardFormatA
関数新しいクリップボード形式を登録しIDを取得する(ANSI版)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
DWORD RegisterClipboardFormatA(
LPCSTR lpszFormat
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszFormat | LPCSTR | in | 新しい形式の名前。 |
戻り値の型: DWORD
公式ドキュメント
新しいクリップボード形式を登録します。登録した形式は、以降は有効なクリップボード形式として使用できます。(ANSI)
戻り値
型: UINT
関数が成功した場合、戻り値は登録されたクリップボード形式を識別する値です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
指定した名前を持つ登録済みの形式が既に存在する場合、新しい形式は登録されず、戻り値は既存の形式を識別します。これにより、複数のアプリケーションが同じ登録済みクリップボード形式を使用してデータのコピーと貼り付けを行えるようになります。なお、形式名の比較は大文字と小文字を区別しません。
登録済みクリップボード形式は、0xC000 から 0xFFFF の範囲の値で識別されます。
登録済みクリップボード形式をクリップボードに格納したり、クリップボードから取得したりする場合、それらは HGLOBAL 値の形式でなければなりません。
例
例については、クリップボード形式の登録 を参照してください。
メモ
winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして RegisterClipboardFormat を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存ではないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規約 を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
DWORD RegisterClipboardFormatA(
LPCSTR lpszFormat
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint RegisterClipboardFormatA(
[MarshalAs(UnmanagedType.LPStr)] string lpszFormat // LPCSTR
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterClipboardFormatA(
<MarshalAs(UnmanagedType.LPStr)> lpszFormat As String ' LPCSTR
) As UInteger
End Function' lpszFormat : LPCSTR
Declare PtrSafe Function RegisterClipboardFormatA Lib "user32" ( _
ByVal lpszFormat As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegisterClipboardFormatA = ctypes.windll.user32.RegisterClipboardFormatA
RegisterClipboardFormatA.restype = wintypes.DWORD
RegisterClipboardFormatA.argtypes = [
wintypes.LPCSTR, # lpszFormat : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
RegisterClipboardFormatA = Fiddle::Function.new(
lib['RegisterClipboardFormatA'],
[
Fiddle::TYPE_VOIDP, # lpszFormat : LPCSTR
],
-Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn RegisterClipboardFormatA(
lpszFormat: *const u8 // LPCSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint RegisterClipboardFormatA([MarshalAs(UnmanagedType.LPStr)] string lpszFormat);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_RegisterClipboardFormatA' -Namespace Win32 -PassThru
# $api::RegisterClipboardFormatA(lpszFormat)#uselib "USER32.dll"
#func global RegisterClipboardFormatA "RegisterClipboardFormatA" sptr
; RegisterClipboardFormatA lpszFormat ; 戻り値は stat
; lpszFormat : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global RegisterClipboardFormatA "RegisterClipboardFormatA" str
; res = RegisterClipboardFormatA(lpszFormat)
; lpszFormat : LPCSTR -> "str"; DWORD RegisterClipboardFormatA(LPCSTR lpszFormat)
#uselib "USER32.dll"
#cfunc global RegisterClipboardFormatA "RegisterClipboardFormatA" str
; res = RegisterClipboardFormatA(lpszFormat)
; lpszFormat : LPCSTR -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procRegisterClipboardFormatA = user32.NewProc("RegisterClipboardFormatA")
)
// lpszFormat (LPCSTR)
r1, _, err := procRegisterClipboardFormatA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszFormat))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction RegisterClipboardFormatA(
lpszFormat: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'USER32.dll' name 'RegisterClipboardFormatA';result := DllCall("USER32\RegisterClipboardFormatA"
, "AStr", lpszFormat ; LPCSTR
, "UInt") ; return: DWORD●RegisterClipboardFormatA(lpszFormat) = DLL("USER32.dll", "dword RegisterClipboardFormatA(char*)")
# 呼び出し: RegisterClipboardFormatA(lpszFormat)
# lpszFormat : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn RegisterClipboardFormatA(
lpszFormat: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) u32;proc RegisterClipboardFormatA(
lpszFormat: cstring # LPCSTR
): uint32 {.importc: "RegisterClipboardFormatA", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
uint RegisterClipboardFormatA(
const(char)* lpszFormat // LPCSTR
);ccall((:RegisterClipboardFormatA, "USER32.dll"), stdcall, UInt32,
(Cstring,),
lpszFormat)
# lpszFormat : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t RegisterClipboardFormatA(
const char* lpszFormat);
]]
local user32 = ffi.load("user32")
-- user32.RegisterClipboardFormatA(lpszFormat)
-- lpszFormat : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const RegisterClipboardFormatA = lib.func('__stdcall', 'RegisterClipboardFormatA', 'uint32_t', ['str']);
// RegisterClipboardFormatA(lpszFormat)
// lpszFormat : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
RegisterClipboardFormatA: { parameters: ["buffer"], result: "u32" },
});
// lib.symbols.RegisterClipboardFormatA(lpszFormat)
// lpszFormat : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RegisterClipboardFormatA(
const char* lpszFormat);
C, "USER32.dll");
// $ffi->RegisterClipboardFormatA(lpszFormat);
// lpszFormat : LPCSTR
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.ASCII_OPTIONS);
int RegisterClipboardFormatA(
String lpszFormat // LPCSTR
);
}@[Link("user32")]
lib LibUSER32
fun RegisterClipboardFormatA = RegisterClipboardFormatA(
lpszFormat : UInt8* # LPCSTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegisterClipboardFormatANative = Uint32 Function(Pointer<Utf8>);
typedef RegisterClipboardFormatADart = int Function(Pointer<Utf8>);
final RegisterClipboardFormatA = DynamicLibrary.open('USER32.dll')
.lookupFunction<RegisterClipboardFormatANative, RegisterClipboardFormatADart>('RegisterClipboardFormatA');
// lpszFormat : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegisterClipboardFormatA(
lpszFormat: PAnsiChar // LPCSTR
): DWORD; stdcall;
external 'USER32.dll' name 'RegisterClipboardFormatA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegisterClipboardFormatA"
c_RegisterClipboardFormatA :: CString -> IO Word32
-- lpszFormat : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let registerclipboardformata =
foreign "RegisterClipboardFormatA"
(string @-> returning uint32_t)
(* lpszFormat : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("RegisterClipboardFormatA" register-clipboard-format-a :convention :stdcall) :uint32
(lpsz-format :string)) ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegisterClipboardFormatA = Win32::API::More->new('USER32',
'DWORD RegisterClipboardFormatA(LPCSTR lpszFormat)');
# my $ret = $RegisterClipboardFormatA->Call($lpszFormat);
# lpszFormat : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f RegisterClipboardFormatW (Unicode版) — 新しいクリップボード形式を登録しIDを取得する(Unicode版)。
公式の関連項目
- f CountClipboardFormats — クリップボード上に現在存在するデータ形式の数を取得する。
- f EnumClipboardFormats — クリップボードで利用可能なデータ形式を順に列挙する。
- f GetClipboardFormatNameA — 登録済みクリップボード形式の名前をANSI文字列で取得する。