DuplicateIcon
関数アイコンを複製して新しいハンドルを返す。
シグネチャ
// SHELL32.dll
#include <windows.h>
HICON DuplicateIcon(
HINSTANCE hInst, // optional
HICON hIcon
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInst | HINSTANCE | optional | |
| hIcon | HICON | in | 複製するアイコンのハンドル。 |
戻り値の型: HICON
公式ドキュメント
指定されたアイコンの複製を作成します。
戻り値
型: HICON
成功した場合、この関数は作成された新しいアイコンのハンドルを返します。失敗した場合は NULL を返します。
解説(Remarks)
複製したアイコンが不要になった場合、DuplicateIcon によって返されたアイコンハンドルは、呼び出し側が DestroyIcon 関数を呼び出して解放する責任があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
HICON DuplicateIcon(
HINSTANCE hInst, // optional
HICON hIcon
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern IntPtr DuplicateIcon(
IntPtr hInst, // HINSTANCE optional
IntPtr hIcon // HICON
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function DuplicateIcon(
hInst As IntPtr, ' HINSTANCE optional
hIcon As IntPtr ' HICON
) As IntPtr
End Function' hInst : HINSTANCE optional
' hIcon : HICON
Declare PtrSafe Function DuplicateIcon Lib "shell32" ( _
ByVal hInst As LongPtr, _
ByVal hIcon As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DuplicateIcon = ctypes.windll.shell32.DuplicateIcon
DuplicateIcon.restype = ctypes.c_void_p
DuplicateIcon.argtypes = [
wintypes.HANDLE, # hInst : HINSTANCE optional
wintypes.HANDLE, # hIcon : HICON
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
DuplicateIcon = Fiddle::Function.new(
lib['DuplicateIcon'],
[
Fiddle::TYPE_VOIDP, # hInst : HINSTANCE optional
Fiddle::TYPE_VOIDP, # hIcon : HICON
],
Fiddle::TYPE_VOIDP)#[link(name = "shell32")]
extern "system" {
fn DuplicateIcon(
hInst: *mut core::ffi::c_void, // HINSTANCE optional
hIcon: *mut core::ffi::c_void // HICON
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern IntPtr DuplicateIcon(IntPtr hInst, IntPtr hIcon);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DuplicateIcon' -Namespace Win32 -PassThru
# $api::DuplicateIcon(hInst, hIcon)#uselib "SHELL32.dll"
#func global DuplicateIcon "DuplicateIcon" sptr, sptr
; DuplicateIcon hInst, hIcon ; 戻り値は stat
; hInst : HINSTANCE optional -> "sptr"
; hIcon : HICON -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global DuplicateIcon "DuplicateIcon" sptr, sptr
; res = DuplicateIcon(hInst, hIcon)
; hInst : HINSTANCE optional -> "sptr"
; hIcon : HICON -> "sptr"; HICON DuplicateIcon(HINSTANCE hInst, HICON hIcon)
#uselib "SHELL32.dll"
#cfunc global DuplicateIcon "DuplicateIcon" intptr, intptr
; res = DuplicateIcon(hInst, hIcon)
; hInst : HINSTANCE optional -> "intptr"
; hIcon : HICON -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procDuplicateIcon = shell32.NewProc("DuplicateIcon")
)
// hInst (HINSTANCE optional), hIcon (HICON)
r1, _, err := procDuplicateIcon.Call(
uintptr(hInst),
uintptr(hIcon),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HICONfunction DuplicateIcon(
hInst: THandle; // HINSTANCE optional
hIcon: THandle // HICON
): THandle; stdcall;
external 'SHELL32.dll' name 'DuplicateIcon';result := DllCall("SHELL32\DuplicateIcon"
, "Ptr", hInst ; HINSTANCE optional
, "Ptr", hIcon ; HICON
, "Ptr") ; return: HICON●DuplicateIcon(hInst, hIcon) = DLL("SHELL32.dll", "void* DuplicateIcon(void*, void*)")
# 呼び出し: DuplicateIcon(hInst, hIcon)
# hInst : HINSTANCE optional -> "void*"
# hIcon : HICON -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn DuplicateIcon(
hInst: ?*anyopaque, // HINSTANCE optional
hIcon: ?*anyopaque // HICON
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc DuplicateIcon(
hInst: pointer, # HINSTANCE optional
hIcon: pointer # HICON
): pointer {.importc: "DuplicateIcon", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void* DuplicateIcon(
void* hInst, // HINSTANCE optional
void* hIcon // HICON
);ccall((:DuplicateIcon, "SHELL32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{Cvoid}),
hInst, hIcon)
# hInst : HINSTANCE optional -> Ptr{Cvoid}
# hIcon : HICON -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* DuplicateIcon(
void* hInst,
void* hIcon);
]]
local shell32 = ffi.load("shell32")
-- shell32.DuplicateIcon(hInst, hIcon)
-- hInst : HINSTANCE optional
-- hIcon : HICON
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const DuplicateIcon = lib.func('__stdcall', 'DuplicateIcon', 'void *', ['void *', 'void *']);
// DuplicateIcon(hInst, hIcon)
// hInst : HINSTANCE optional -> 'void *'
// hIcon : HICON -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
DuplicateIcon: { parameters: ["pointer", "pointer"], result: "pointer" },
});
// lib.symbols.DuplicateIcon(hInst, hIcon)
// hInst : HINSTANCE optional -> "pointer"
// hIcon : HICON -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* DuplicateIcon(
void* hInst,
void* hIcon);
C, "SHELL32.dll");
// $ffi->DuplicateIcon(hInst, hIcon);
// hInst : HINSTANCE optional
// hIcon : HICON
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
Pointer DuplicateIcon(
Pointer hInst, // HINSTANCE optional
Pointer hIcon // HICON
);
}@[Link("shell32")]
lib LibSHELL32
fun DuplicateIcon = DuplicateIcon(
hInst : Void*, # HINSTANCE optional
hIcon : Void* # HICON
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DuplicateIconNative = Pointer<Void> Function(Pointer<Void>, Pointer<Void>);
typedef DuplicateIconDart = Pointer<Void> Function(Pointer<Void>, Pointer<Void>);
final DuplicateIcon = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<DuplicateIconNative, DuplicateIconDart>('DuplicateIcon');
// hInst : HINSTANCE optional -> Pointer<Void>
// hIcon : HICON -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DuplicateIcon(
hInst: THandle; // HINSTANCE optional
hIcon: THandle // HICON
): THandle; stdcall;
external 'SHELL32.dll' name 'DuplicateIcon';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DuplicateIcon"
c_DuplicateIcon :: Ptr () -> Ptr () -> IO (Ptr ())
-- hInst : HINSTANCE optional -> Ptr ()
-- hIcon : HICON -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let duplicateicon =
foreign "DuplicateIcon"
((ptr void) @-> (ptr void) @-> returning (ptr void))
(* hInst : HINSTANCE optional -> (ptr void) *)
(* hIcon : HICON -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("DuplicateIcon" duplicate-icon :convention :stdcall) :pointer
(h-inst :pointer) ; HINSTANCE optional
(h-icon :pointer)) ; HICON
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DuplicateIcon = Win32::API::More->new('SHELL32',
'HANDLE DuplicateIcon(HANDLE hInst, HANDLE hIcon)');
# my $ret = $DuplicateIcon->Call($hInst, $hIcon);
# hInst : HINSTANCE optional -> HANDLE
# hIcon : HICON -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。