Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › ImageAddCertificate

ImageAddCertificate

関数
イメージファイルに証明書を追加する。
DLLimagehlp.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL ImageAddCertificate(
    HANDLE FileHandle,
    WIN_CERTIFICATE* Certificate,
    DWORD* Index
);

パラメーター

名前方向
FileHandleHANDLEin
CertificateWIN_CERTIFICATE*in
IndexDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL ImageAddCertificate(
    HANDLE FileHandle,
    WIN_CERTIFICATE* Certificate,
    DWORD* Index
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ImageAddCertificate(
    IntPtr FileHandle,   // HANDLE
    IntPtr Certificate,   // WIN_CERTIFICATE*
    out uint Index   // DWORD* out
);
<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ImageAddCertificate(
    FileHandle As IntPtr,   ' HANDLE
    Certificate As IntPtr,   ' WIN_CERTIFICATE*
    <Out> ByRef Index As UInteger   ' DWORD* out
) As Boolean
End Function
' FileHandle : HANDLE
' Certificate : WIN_CERTIFICATE*
' Index : DWORD* out
Declare PtrSafe Function ImageAddCertificate Lib "imagehlp" ( _
    ByVal FileHandle As LongPtr, _
    ByVal Certificate As LongPtr, _
    ByRef Index As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ImageAddCertificate = ctypes.windll.imagehlp.ImageAddCertificate
ImageAddCertificate.restype = wintypes.BOOL
ImageAddCertificate.argtypes = [
    wintypes.HANDLE,  # FileHandle : HANDLE
    ctypes.c_void_p,  # Certificate : WIN_CERTIFICATE*
    ctypes.POINTER(wintypes.DWORD),  # Index : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('imagehlp.dll')
ImageAddCertificate = Fiddle::Function.new(
  lib['ImageAddCertificate'],
  [
    Fiddle::TYPE_VOIDP,  # FileHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # Certificate : WIN_CERTIFICATE*
    Fiddle::TYPE_VOIDP,  # Index : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "imagehlp")]
extern "system" {
    fn ImageAddCertificate(
        FileHandle: *mut core::ffi::c_void,  // HANDLE
        Certificate: *mut WIN_CERTIFICATE,  // WIN_CERTIFICATE*
        Index: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true)]
public static extern bool ImageAddCertificate(IntPtr FileHandle, IntPtr Certificate, out uint Index);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_ImageAddCertificate' -Namespace Win32 -PassThru
# $api::ImageAddCertificate(FileHandle, Certificate, Index)
#uselib "imagehlp.dll"
#func global ImageAddCertificate "ImageAddCertificate" sptr, sptr, sptr
; ImageAddCertificate FileHandle, varptr(Certificate), varptr(Index)   ; 戻り値は stat
; FileHandle : HANDLE -> "sptr"
; Certificate : WIN_CERTIFICATE* -> "sptr"
; Index : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "imagehlp.dll"
#cfunc global ImageAddCertificate "ImageAddCertificate" sptr, var, var
; res = ImageAddCertificate(FileHandle, Certificate, Index)
; FileHandle : HANDLE -> "sptr"
; Certificate : WIN_CERTIFICATE* -> "var"
; Index : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ImageAddCertificate(HANDLE FileHandle, WIN_CERTIFICATE* Certificate, DWORD* Index)
#uselib "imagehlp.dll"
#cfunc global ImageAddCertificate "ImageAddCertificate" intptr, var, var
; res = ImageAddCertificate(FileHandle, Certificate, Index)
; FileHandle : HANDLE -> "intptr"
; Certificate : WIN_CERTIFICATE* -> "var"
; Index : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
	procImageAddCertificate = imagehlp.NewProc("ImageAddCertificate")
)

// FileHandle (HANDLE), Certificate (WIN_CERTIFICATE*), Index (DWORD* out)
r1, _, err := procImageAddCertificate.Call(
	uintptr(FileHandle),
	uintptr(Certificate),
	uintptr(Index),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ImageAddCertificate(
  FileHandle: THandle;   // HANDLE
  Certificate: Pointer;   // WIN_CERTIFICATE*
  Index: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'imagehlp.dll' name 'ImageAddCertificate';
result := DllCall("imagehlp\ImageAddCertificate"
    , "Ptr", FileHandle   ; HANDLE
    , "Ptr", Certificate   ; WIN_CERTIFICATE*
    , "Ptr", Index   ; DWORD* out
    , "Int")   ; return: BOOL
●ImageAddCertificate(FileHandle, Certificate, Index) = DLL("imagehlp.dll", "bool ImageAddCertificate(void*, void*, void*)")
# 呼び出し: ImageAddCertificate(FileHandle, Certificate, Index)
# FileHandle : HANDLE -> "void*"
# Certificate : WIN_CERTIFICATE* -> "void*"
# Index : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。