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

OleGetIconOfFile

関数
指定ファイルに関連付けられたアイコンを取得する。
DLLole32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// ole32.dll
#include <windows.h>

HGLOBAL OleGetIconOfFile(
    LPWSTR lpszPath,
    BOOL fUseFileAsLabel
);

パラメーター

名前方向
lpszPathLPWSTRin
fUseFileAsLabelBOOLin

戻り値の型: HGLOBAL

各言語での呼び出し定義

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