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

MsiDoActionA

関数
指定したインストールアクションを実行する(ANSI版)。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiDoActionA(
    MSIHANDLE hInstall,
    LPCSTR szAction
);

パラメーター

名前方向説明
hInstallMSIHANDLEinDLL カスタムアクションに提供された、または MsiOpenPackageMsiOpenPackageExMsiOpenProduct を通じて取得したインストールのハンドルです。
szActionLPCSTRin実行するアクションを指定します。

戻り値の型: DWORD

公式ドキュメント

MsiDoAction 関数は、組み込みアクション、カスタムアクション、またはユーザーインターフェイスウィザードアクションを実行します。(ANSI)

戻り値

この関数は UINT を返します。

解説(Remarks)

MsiDoAction 関数は、指定された名前に対応するアクションを実行します。その名前が組み込みアクションとして、または CustomAction テーブル内のカスタムアクションとしてインストーラーに認識されない場合、その名前はユーザーインターフェイスハンドラーオブジェクトに渡され、関数またはダイアログボックスを呼び出すことができます。null のアクション名が指定された場合、インストーラーは ACTION プロパティの大文字の値を実行するアクションとして使用します。プロパティ値が定義されていない場合は、既定のアクションが実行されます。既定のアクションは "INSTALL" として定義されています。

InstallFiles アクションや WriteRegistryValues アクションなど、システムを更新するアクションは、 MsiDoAction を呼び出して実行することはできません。このルールの例外は、 InstallExecuteSequence テーブル内で InstallInitialize アクションと InstallFinalize アクションの間にスケジュールされたカスタムアクションから MsiDoAction が呼び出される場合です。 AppSearchCostInitialize など、システムを更新しないアクションは呼び出すことができます。

メモ

msiquery.h ヘッダーは MsiDoAction を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiDoActionA(
    MSIHANDLE hInstall,
    LPCSTR szAction
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiDoActionA(
    uint hInstall,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPStr)] string szAction   // LPCSTR
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiDoActionA(
    hInstall As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPStr)> szAction As String   ' LPCSTR
) As UInteger
End Function
' hInstall : MSIHANDLE
' szAction : LPCSTR
Declare PtrSafe Function MsiDoActionA Lib "msi" ( _
    ByVal hInstall As Long, _
    ByVal szAction As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiDoActionA = ctypes.windll.msi.MsiDoActionA
MsiDoActionA.restype = wintypes.DWORD
MsiDoActionA.argtypes = [
    wintypes.DWORD,  # hInstall : MSIHANDLE
    wintypes.LPCSTR,  # szAction : LPCSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiDoActionA = Fiddle::Function.new(
  lib['MsiDoActionA'],
  [
    -Fiddle::TYPE_INT,  # hInstall : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szAction : LPCSTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "msi")]
extern "system" {
    fn MsiDoActionA(
        hInstall: u32,  // MSIHANDLE
        szAction: *const u8  // LPCSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiDoActionA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szAction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiDoActionA' -Namespace Win32 -PassThru
# $api::MsiDoActionA(hInstall, szAction)
#uselib "msi.dll"
#func global MsiDoActionA "MsiDoActionA" sptr, sptr
; MsiDoActionA hInstall, szAction   ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szAction : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiDoActionA "MsiDoActionA" int, str
; res = MsiDoActionA(hInstall, szAction)
; hInstall : MSIHANDLE -> "int"
; szAction : LPCSTR -> "str"
; DWORD MsiDoActionA(MSIHANDLE hInstall, LPCSTR szAction)
#uselib "msi.dll"
#cfunc global MsiDoActionA "MsiDoActionA" int, str
; res = MsiDoActionA(hInstall, szAction)
; hInstall : MSIHANDLE -> "int"
; szAction : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiDoActionA = msi.NewProc("MsiDoActionA")
)

// hInstall (MSIHANDLE), szAction (LPCSTR)
r1, _, err := procMsiDoActionA.Call(
	uintptr(hInstall),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szAction))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiDoActionA(
  hInstall: DWORD;   // MSIHANDLE
  szAction: PAnsiChar   // LPCSTR
): DWORD; stdcall;
  external 'msi.dll' name 'MsiDoActionA';
result := DllCall("msi\MsiDoActionA"
    , "UInt", hInstall   ; MSIHANDLE
    , "AStr", szAction   ; LPCSTR
    , "UInt")   ; return: DWORD
●MsiDoActionA(hInstall, szAction) = DLL("msi.dll", "dword MsiDoActionA(dword, char*)")
# 呼び出し: MsiDoActionA(hInstall, szAction)
# hInstall : MSIHANDLE -> "dword"
# szAction : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "msi" fn MsiDoActionA(
    hInstall: u32, // MSIHANDLE
    szAction: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) u32;
proc MsiDoActionA(
    hInstall: uint32,  # MSIHANDLE
    szAction: cstring  # LPCSTR
): uint32 {.importc: "MsiDoActionA", stdcall, dynlib: "msi.dll".}
pragma(lib, "msi");
extern(Windows)
uint MsiDoActionA(
    uint hInstall,   // MSIHANDLE
    const(char)* szAction   // LPCSTR
);
ccall((:MsiDoActionA, "msi.dll"), stdcall, UInt32,
      (UInt32, Cstring),
      hInstall, szAction)
# hInstall : MSIHANDLE -> UInt32
# szAction : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiDoActionA(
    uint32_t hInstall,
    const char* szAction);
]]
local msi = ffi.load("msi")
-- msi.MsiDoActionA(hInstall, szAction)
-- hInstall : MSIHANDLE
-- szAction : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiDoActionA = lib.func('__stdcall', 'MsiDoActionA', 'uint32_t', ['uint32_t', 'str']);
// MsiDoActionA(hInstall, szAction)
// hInstall : MSIHANDLE -> 'uint32_t'
// szAction : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiDoActionA: { parameters: ["u32", "buffer"], result: "u32" },
});
// lib.symbols.MsiDoActionA(hInstall, szAction)
// hInstall : MSIHANDLE -> "u32"
// szAction : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiDoActionA(
    uint32_t hInstall,
    const char* szAction);
C, "msi.dll");
// $ffi->MsiDoActionA(hInstall, szAction);
// hInstall : MSIHANDLE
// szAction : LPCSTR
// 構造体/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 Msi extends StdCallLibrary {
    Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
    int MsiDoActionA(
        int hInstall,   // MSIHANDLE
        String szAction   // LPCSTR
    );
}
@[Link("msi")]
lib Libmsi
  fun MsiDoActionA = MsiDoActionA(
    hInstall : UInt32,   # MSIHANDLE
    szAction : UInt8*   # LPCSTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiDoActionANative = Uint32 Function(Uint32, Pointer<Utf8>);
typedef MsiDoActionADart = int Function(int, Pointer<Utf8>);
final MsiDoActionA = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiDoActionANative, MsiDoActionADart>('MsiDoActionA');
// hInstall : MSIHANDLE -> Uint32
// szAction : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiDoActionA(
  hInstall: DWORD;   // MSIHANDLE
  szAction: PAnsiChar   // LPCSTR
): DWORD; stdcall;
  external 'msi.dll' name 'MsiDoActionA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiDoActionA"
  c_MsiDoActionA :: Word32 -> CString -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szAction : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msidoactiona =
  foreign "MsiDoActionA"
    (uint32_t @-> string @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szAction : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiDoActionA" msi-do-action-a :convention :stdcall) :uint32
  (h-install :uint32)   ; MSIHANDLE
  (sz-action :string))   ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiDoActionA = Win32::API::More->new('msi',
    'DWORD MsiDoActionA(DWORD hInstall, LPCSTR szAction)');
# my $ret = $MsiDoActionA->Call($hInstall, $szAction);
# hInstall : MSIHANDLE -> DWORD
# szAction : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い