ホーム › Web.InternetExplorer › IdentifyMIMEType
IdentifyMIMEType
関数先頭バイト列からデータのMIMEフォーマット種別を識別する。
シグネチャ
// ImgUtil.dll
#include <windows.h>
HRESULT IdentifyMIMEType(
const BYTE* pbBytes,
DWORD nBytes,
DWORD* pnFormat
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pbBytes | BYTE* | in | MIME型を判定する先頭バイト列を格納したバッファへのポインタを指定する。 |
| nBytes | DWORD | in | pbBytesの有効バイト数を指定する。 |
| pnFormat | DWORD* | inout | 判定された画像形式を表す識別子を受け取るDWORDへのポインタを指定する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// ImgUtil.dll
#include <windows.h>
HRESULT IdentifyMIMEType(
const BYTE* pbBytes,
DWORD nBytes,
DWORD* pnFormat
);[DllImport("ImgUtil.dll", ExactSpelling = true)]
static extern int IdentifyMIMEType(
IntPtr pbBytes, // BYTE*
uint nBytes, // DWORD
ref uint pnFormat // DWORD* in/out
);<DllImport("ImgUtil.dll", ExactSpelling:=True)>
Public Shared Function IdentifyMIMEType(
pbBytes As IntPtr, ' BYTE*
nBytes As UInteger, ' DWORD
ByRef pnFormat As UInteger ' DWORD* in/out
) As Integer
End Function' pbBytes : BYTE*
' nBytes : DWORD
' pnFormat : DWORD* in/out
Declare PtrSafe Function IdentifyMIMEType Lib "imgutil" ( _
ByVal pbBytes As LongPtr, _
ByVal nBytes As Long, _
ByRef pnFormat As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
IdentifyMIMEType = ctypes.windll.imgutil.IdentifyMIMEType
IdentifyMIMEType.restype = ctypes.c_int
IdentifyMIMEType.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # pbBytes : BYTE*
wintypes.DWORD, # nBytes : DWORD
ctypes.POINTER(wintypes.DWORD), # pnFormat : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ImgUtil.dll')
IdentifyMIMEType = Fiddle::Function.new(
lib['IdentifyMIMEType'],
[
Fiddle::TYPE_VOIDP, # pbBytes : BYTE*
-Fiddle::TYPE_INT, # nBytes : DWORD
Fiddle::TYPE_VOIDP, # pnFormat : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "imgutil")]
extern "system" {
fn IdentifyMIMEType(
pbBytes: *const u8, // BYTE*
nBytes: u32, // DWORD
pnFormat: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ImgUtil.dll")]
public static extern int IdentifyMIMEType(IntPtr pbBytes, uint nBytes, ref uint pnFormat);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ImgUtil_IdentifyMIMEType' -Namespace Win32 -PassThru
# $api::IdentifyMIMEType(pbBytes, nBytes, pnFormat)#uselib "ImgUtil.dll"
#func global IdentifyMIMEType "IdentifyMIMEType" sptr, sptr, sptr
; IdentifyMIMEType varptr(pbBytes), nBytes, varptr(pnFormat) ; 戻り値は stat
; pbBytes : BYTE* -> "sptr"
; nBytes : DWORD -> "sptr"
; pnFormat : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ImgUtil.dll" #cfunc global IdentifyMIMEType "IdentifyMIMEType" var, int, var ; res = IdentifyMIMEType(pbBytes, nBytes, pnFormat) ; pbBytes : BYTE* -> "var" ; nBytes : DWORD -> "int" ; pnFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ImgUtil.dll" #cfunc global IdentifyMIMEType "IdentifyMIMEType" sptr, int, sptr ; res = IdentifyMIMEType(varptr(pbBytes), nBytes, varptr(pnFormat)) ; pbBytes : BYTE* -> "sptr" ; nBytes : DWORD -> "int" ; pnFormat : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT IdentifyMIMEType(BYTE* pbBytes, DWORD nBytes, DWORD* pnFormat) #uselib "ImgUtil.dll" #cfunc global IdentifyMIMEType "IdentifyMIMEType" var, int, var ; res = IdentifyMIMEType(pbBytes, nBytes, pnFormat) ; pbBytes : BYTE* -> "var" ; nBytes : DWORD -> "int" ; pnFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT IdentifyMIMEType(BYTE* pbBytes, DWORD nBytes, DWORD* pnFormat) #uselib "ImgUtil.dll" #cfunc global IdentifyMIMEType "IdentifyMIMEType" intptr, int, intptr ; res = IdentifyMIMEType(varptr(pbBytes), nBytes, varptr(pnFormat)) ; pbBytes : BYTE* -> "intptr" ; nBytes : DWORD -> "int" ; pnFormat : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
imgutil = windows.NewLazySystemDLL("ImgUtil.dll")
procIdentifyMIMEType = imgutil.NewProc("IdentifyMIMEType")
)
// pbBytes (BYTE*), nBytes (DWORD), pnFormat (DWORD* in/out)
r1, _, err := procIdentifyMIMEType.Call(
uintptr(pbBytes),
uintptr(nBytes),
uintptr(pnFormat),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction IdentifyMIMEType(
pbBytes: Pointer; // BYTE*
nBytes: DWORD; // DWORD
pnFormat: Pointer // DWORD* in/out
): Integer; stdcall;
external 'ImgUtil.dll' name 'IdentifyMIMEType';result := DllCall("ImgUtil\IdentifyMIMEType"
, "Ptr", pbBytes ; BYTE*
, "UInt", nBytes ; DWORD
, "Ptr", pnFormat ; DWORD* in/out
, "Int") ; return: HRESULT●IdentifyMIMEType(pbBytes, nBytes, pnFormat) = DLL("ImgUtil.dll", "int IdentifyMIMEType(void*, dword, void*)")
# 呼び出し: IdentifyMIMEType(pbBytes, nBytes, pnFormat)
# pbBytes : BYTE* -> "void*"
# nBytes : DWORD -> "dword"
# pnFormat : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "imgutil" fn IdentifyMIMEType(
pbBytes: [*c]u8, // BYTE*
nBytes: u32, // DWORD
pnFormat: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc IdentifyMIMEType(
pbBytes: ptr uint8, # BYTE*
nBytes: uint32, # DWORD
pnFormat: ptr uint32 # DWORD* in/out
): int32 {.importc: "IdentifyMIMEType", stdcall, dynlib: "ImgUtil.dll".}pragma(lib, "imgutil");
extern(Windows)
int IdentifyMIMEType(
ubyte* pbBytes, // BYTE*
uint nBytes, // DWORD
uint* pnFormat // DWORD* in/out
);ccall((:IdentifyMIMEType, "ImgUtil.dll"), stdcall, Int32,
(Ptr{UInt8}, UInt32, Ptr{UInt32}),
pbBytes, nBytes, pnFormat)
# pbBytes : BYTE* -> Ptr{UInt8}
# nBytes : DWORD -> UInt32
# pnFormat : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t IdentifyMIMEType(
uint8_t* pbBytes,
uint32_t nBytes,
uint32_t* pnFormat);
]]
local imgutil = ffi.load("imgutil")
-- imgutil.IdentifyMIMEType(pbBytes, nBytes, pnFormat)
-- pbBytes : BYTE*
-- nBytes : DWORD
-- pnFormat : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ImgUtil.dll');
const IdentifyMIMEType = lib.func('__stdcall', 'IdentifyMIMEType', 'int32_t', ['uint8_t *', 'uint32_t', 'uint32_t *']);
// IdentifyMIMEType(pbBytes, nBytes, pnFormat)
// pbBytes : BYTE* -> 'uint8_t *'
// nBytes : DWORD -> 'uint32_t'
// pnFormat : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ImgUtil.dll", {
IdentifyMIMEType: { parameters: ["pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.IdentifyMIMEType(pbBytes, nBytes, pnFormat)
// pbBytes : BYTE* -> "pointer"
// nBytes : DWORD -> "u32"
// pnFormat : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t IdentifyMIMEType(
uint8_t* pbBytes,
uint32_t nBytes,
uint32_t* pnFormat);
C, "ImgUtil.dll");
// $ffi->IdentifyMIMEType(pbBytes, nBytes, pnFormat);
// pbBytes : BYTE*
// nBytes : DWORD
// pnFormat : DWORD* in/out
// 構造体/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 Imgutil extends StdCallLibrary {
Imgutil INSTANCE = Native.load("imgutil", Imgutil.class);
int IdentifyMIMEType(
byte[] pbBytes, // BYTE*
int nBytes, // DWORD
IntByReference pnFormat // DWORD* in/out
);
}@[Link("imgutil")]
lib LibImgUtil
fun IdentifyMIMEType = IdentifyMIMEType(
pbBytes : UInt8*, # BYTE*
nBytes : UInt32, # DWORD
pnFormat : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef IdentifyMIMETypeNative = Int32 Function(Pointer<Uint8>, Uint32, Pointer<Uint32>);
typedef IdentifyMIMETypeDart = int Function(Pointer<Uint8>, int, Pointer<Uint32>);
final IdentifyMIMEType = DynamicLibrary.open('ImgUtil.dll')
.lookupFunction<IdentifyMIMETypeNative, IdentifyMIMETypeDart>('IdentifyMIMEType');
// pbBytes : BYTE* -> Pointer<Uint8>
// nBytes : DWORD -> Uint32
// pnFormat : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function IdentifyMIMEType(
pbBytes: Pointer; // BYTE*
nBytes: DWORD; // DWORD
pnFormat: Pointer // DWORD* in/out
): Integer; stdcall;
external 'ImgUtil.dll' name 'IdentifyMIMEType';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "IdentifyMIMEType"
c_IdentifyMIMEType :: Ptr Word8 -> Word32 -> Ptr Word32 -> IO Int32
-- pbBytes : BYTE* -> Ptr Word8
-- nBytes : DWORD -> Word32
-- pnFormat : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let identifymimetype =
foreign "IdentifyMIMEType"
((ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* pbBytes : BYTE* -> (ptr uint8_t) *)
(* nBytes : DWORD -> uint32_t *)
(* pnFormat : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library imgutil (t "ImgUtil.dll"))
(cffi:use-foreign-library imgutil)
(cffi:defcfun ("IdentifyMIMEType" identify-mimetype :convention :stdcall) :int32
(pb-bytes :pointer) ; BYTE*
(n-bytes :uint32) ; DWORD
(pn-format :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $IdentifyMIMEType = Win32::API::More->new('ImgUtil',
'int IdentifyMIMEType(LPVOID pbBytes, DWORD nBytes, LPVOID pnFormat)');
# my $ret = $IdentifyMIMEType->Call($pbBytes, $nBytes, $pnFormat);
# pbBytes : BYTE* -> LPVOID
# nBytes : DWORD -> DWORD
# pnFormat : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。