ホーム › System.Ole › OleGetIconOfFile
OleGetIconOfFile
関数指定ファイルに関連付けられたアイコンを取得する。
シグネチャ
// OLE32.dll
#include <windows.h>
HGLOBAL OleGetIconOfFile(
LPWSTR lpszPath,
BOOL fUseFileAsLabel
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszPath | LPWSTR | in | アイコンと文字列を要求する対象のファイルへのポインター。 |
| fUseFileAsLabel | BOOL | in | ファイル名をアイコンのラベルとして使用するかどうかを示します。 |
戻り値の型: HGLOBAL
公式ドキュメント
指定されたファイル名に対するアイコンと文字列ラベルを含むメタファイルへのハンドルを返します。
戻り値
関数が成功した場合、戻り値は指定されたファイルのアイコンとラベルを含むメタファイルへのハンドルです。登録データベースにそのファイルの CLSID が存在しない場合、関数は文字列 "Document" を返します。lpszPath が NULL の場合、関数は NULL を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLE32.dll
#include <windows.h>
HGLOBAL OleGetIconOfFile(
LPWSTR lpszPath,
BOOL fUseFileAsLabel
);[DllImport("OLE32.dll", ExactSpelling = true)]
static extern IntPtr OleGetIconOfFile(
[MarshalAs(UnmanagedType.LPWStr)] string lpszPath, // LPWSTR
bool fUseFileAsLabel // BOOL
);<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function OleGetIconOfFile(
<MarshalAs(UnmanagedType.LPWStr)> lpszPath As String, ' LPWSTR
fUseFileAsLabel As Boolean ' BOOL
) As IntPtr
End Function' lpszPath : LPWSTR
' fUseFileAsLabel : BOOL
Declare PtrSafe Function OleGetIconOfFile Lib "ole32" ( _
ByVal lpszPath As LongPtr, _
ByVal fUseFileAsLabel As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OleGetIconOfFile = ctypes.windll.ole32.OleGetIconOfFile
OleGetIconOfFile.restype = ctypes.c_void_p
OleGetIconOfFile.argtypes = [
wintypes.LPCWSTR, # lpszPath : LPWSTR
wintypes.BOOL, # fUseFileAsLabel : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLE32.dll')
OleGetIconOfFile = Fiddle::Function.new(
lib['OleGetIconOfFile'],
[
Fiddle::TYPE_VOIDP, # lpszPath : LPWSTR
Fiddle::TYPE_INT, # fUseFileAsLabel : BOOL
],
Fiddle::TYPE_VOIDP)#[link(name = "ole32")]
extern "system" {
fn OleGetIconOfFile(
lpszPath: *mut u16, // LPWSTR
fUseFileAsLabel: i32 // BOOL
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLE32.dll")]
public static extern IntPtr OleGetIconOfFile([MarshalAs(UnmanagedType.LPWStr)] string lpszPath, bool fUseFileAsLabel);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_OleGetIconOfFile' -Namespace Win32 -PassThru
# $api::OleGetIconOfFile(lpszPath, fUseFileAsLabel)#uselib "OLE32.dll"
#func global OleGetIconOfFile "OleGetIconOfFile" sptr, sptr
; OleGetIconOfFile lpszPath, fUseFileAsLabel ; 戻り値は stat
; lpszPath : LPWSTR -> "sptr"
; fUseFileAsLabel : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "OLE32.dll"
#cfunc global OleGetIconOfFile "OleGetIconOfFile" wstr, int
; res = OleGetIconOfFile(lpszPath, fUseFileAsLabel)
; lpszPath : LPWSTR -> "wstr"
; fUseFileAsLabel : BOOL -> "int"; HGLOBAL OleGetIconOfFile(LPWSTR lpszPath, BOOL fUseFileAsLabel)
#uselib "OLE32.dll"
#cfunc global OleGetIconOfFile "OleGetIconOfFile" wstr, int
; res = OleGetIconOfFile(lpszPath, fUseFileAsLabel)
; lpszPath : LPWSTR -> "wstr"
; fUseFileAsLabel : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ole32 = windows.NewLazySystemDLL("OLE32.dll")
procOleGetIconOfFile = ole32.NewProc("OleGetIconOfFile")
)
// lpszPath (LPWSTR), fUseFileAsLabel (BOOL)
r1, _, err := procOleGetIconOfFile.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszPath))),
uintptr(fUseFileAsLabel),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HGLOBALfunction OleGetIconOfFile(
lpszPath: PWideChar; // LPWSTR
fUseFileAsLabel: BOOL // BOOL
): THandle; stdcall;
external 'OLE32.dll' name 'OleGetIconOfFile';result := DllCall("OLE32\OleGetIconOfFile"
, "WStr", lpszPath ; LPWSTR
, "Int", fUseFileAsLabel ; BOOL
, "Ptr") ; return: HGLOBAL●OleGetIconOfFile(lpszPath, fUseFileAsLabel) = DLL("OLE32.dll", "void* OleGetIconOfFile(char*, bool)")
# 呼び出し: OleGetIconOfFile(lpszPath, fUseFileAsLabel)
# lpszPath : LPWSTR -> "char*"
# fUseFileAsLabel : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ole32" fn OleGetIconOfFile(
lpszPath: [*c]const u16, // LPWSTR
fUseFileAsLabel: i32 // BOOL
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc OleGetIconOfFile(
lpszPath: WideCString, # LPWSTR
fUseFileAsLabel: int32 # BOOL
): pointer {.importc: "OleGetIconOfFile", stdcall, dynlib: "OLE32.dll".}pragma(lib, "ole32");
extern(Windows)
void* OleGetIconOfFile(
const(wchar)* lpszPath, // LPWSTR
int fUseFileAsLabel // BOOL
);ccall((:OleGetIconOfFile, "OLE32.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Int32),
lpszPath, fUseFileAsLabel)
# lpszPath : LPWSTR -> Cwstring
# fUseFileAsLabel : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* OleGetIconOfFile(
const uint16_t* lpszPath,
int32_t fUseFileAsLabel);
]]
local ole32 = ffi.load("ole32")
-- ole32.OleGetIconOfFile(lpszPath, fUseFileAsLabel)
-- lpszPath : LPWSTR
-- fUseFileAsLabel : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const OleGetIconOfFile = lib.func('__stdcall', 'OleGetIconOfFile', 'void *', ['str16', 'int32_t']);
// OleGetIconOfFile(lpszPath, fUseFileAsLabel)
// lpszPath : LPWSTR -> 'str16'
// fUseFileAsLabel : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLE32.dll", {
OleGetIconOfFile: { parameters: ["buffer", "i32"], result: "pointer" },
});
// lib.symbols.OleGetIconOfFile(lpszPath, fUseFileAsLabel)
// lpszPath : LPWSTR -> "buffer"
// fUseFileAsLabel : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* OleGetIconOfFile(
const uint16_t* lpszPath,
int32_t fUseFileAsLabel);
C, "OLE32.dll");
// $ffi->OleGetIconOfFile(lpszPath, fUseFileAsLabel);
// lpszPath : LPWSTR
// fUseFileAsLabel : BOOL
// 構造体/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 Ole32 extends StdCallLibrary {
Ole32 INSTANCE = Native.load("ole32", Ole32.class);
Pointer OleGetIconOfFile(
WString lpszPath, // LPWSTR
boolean fUseFileAsLabel // BOOL
);
}@[Link("ole32")]
lib LibOLE32
fun OleGetIconOfFile = OleGetIconOfFile(
lpszPath : UInt16*, # LPWSTR
fUseFileAsLabel : Int32 # BOOL
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OleGetIconOfFileNative = Pointer<Void> Function(Pointer<Utf16>, Int32);
typedef OleGetIconOfFileDart = Pointer<Void> Function(Pointer<Utf16>, int);
final OleGetIconOfFile = DynamicLibrary.open('OLE32.dll')
.lookupFunction<OleGetIconOfFileNative, OleGetIconOfFileDart>('OleGetIconOfFile');
// lpszPath : LPWSTR -> Pointer<Utf16>
// fUseFileAsLabel : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function OleGetIconOfFile(
lpszPath: PWideChar; // LPWSTR
fUseFileAsLabel: BOOL // BOOL
): THandle; stdcall;
external 'OLE32.dll' name 'OleGetIconOfFile';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OleGetIconOfFile"
c_OleGetIconOfFile :: CWString -> CInt -> IO (Ptr ())
-- lpszPath : LPWSTR -> CWString
-- fUseFileAsLabel : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let olegeticonoffile =
foreign "OleGetIconOfFile"
((ptr uint16_t) @-> int32_t @-> returning (ptr void))
(* lpszPath : LPWSTR -> (ptr uint16_t) *)
(* fUseFileAsLabel : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)
(cffi:defcfun ("OleGetIconOfFile" ole-get-icon-of-file :convention :stdcall) :pointer
(lpsz-path (:string :encoding :utf-16le)) ; LPWSTR
(f-use-file-as-label :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OleGetIconOfFile = Win32::API::More->new('OLE32',
'HANDLE OleGetIconOfFile(LPCWSTR lpszPath, BOOL fUseFileAsLabel)');
# my $ret = $OleGetIconOfFile->Call($lpszPath, $fUseFileAsLabel);
# lpszPath : LPWSTR -> LPCWSTR
# fUseFileAsLabel : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f OleGetIconOfClass — 指定CLSIDのクラスに関連付けられたアイコンを取得する。
- f OleMetafilePictFromIconAndLabel — アイコンとラベルからメタファイルピクチャを作成する。