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

RegisterClipboardFormatA

関数
新しいクリップボード形式を登録しIDを取得する(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

DWORD RegisterClipboardFormatA(
    LPCSTR lpszFormat
);

パラメーター

名前方向
lpszFormatLPCSTRin

戻り値の型: DWORD

各言語での呼び出し定義

// 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   // DWORD
function 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)。