ホーム › System.ApplicationInstallationAndServicing › MsiGetComponentStateA
MsiGetComponentStateA
関数コンポーネントの現在の状態と要求された状態を取得する(ANSI版)。
シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetComponentStateA(
MSIHANDLE hInstall,
LPCSTR szComponent,
INSTALLSTATE* piInstalled,
INSTALLSTATE* piAction
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに渡された、または MsiOpenPackage、MsiOpenPackageEx、もしくは MsiOpenProduct によって取得したインストールへのハンドル。 |
| szComponent | LPCSTR | in | 製品内のコンポーネント名を指定する、null で終端された文字列。 |
| piInstalled | INSTALLSTATE* | inout | 現在のインストール状態を受け取ります。このパラメーターは null にできません。このパラメーターには次のいずれかの値を指定できます。 |
| piAction | INSTALLSTATE* | inout | インストール中に実行されたアクションを受け取ります。このパラメーターは null にできません。戻り値については piInstalled を参照してください。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetComponentState 関数はコンポーネントの状態を取得します。(ANSI)
戻り値
MsiGetComponentState 関数は次の値を返します。
解説(Remarks)
関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
詳細については、Calling Database Functions From Programs を参照してください。
メモ
msiquery.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetComponentState を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetComponentStateA(
MSIHANDLE hInstall,
LPCSTR szComponent,
INSTALLSTATE* piInstalled,
INSTALLSTATE* piAction
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetComponentStateA(
uint hInstall, // MSIHANDLE
[MarshalAs(UnmanagedType.LPStr)] string szComponent, // LPCSTR
ref int piInstalled, // INSTALLSTATE* in/out
ref int piAction // INSTALLSTATE* in/out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetComponentStateA(
hInstall As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPStr)> szComponent As String, ' LPCSTR
ByRef piInstalled As Integer, ' INSTALLSTATE* in/out
ByRef piAction As Integer ' INSTALLSTATE* in/out
) As UInteger
End Function' hInstall : MSIHANDLE
' szComponent : LPCSTR
' piInstalled : INSTALLSTATE* in/out
' piAction : INSTALLSTATE* in/out
Declare PtrSafe Function MsiGetComponentStateA Lib "msi" ( _
ByVal hInstall As Long, _
ByVal szComponent As String, _
ByRef piInstalled As Long, _
ByRef piAction As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetComponentStateA = ctypes.windll.msi.MsiGetComponentStateA
MsiGetComponentStateA.restype = wintypes.DWORD
MsiGetComponentStateA.argtypes = [
wintypes.DWORD, # hInstall : MSIHANDLE
wintypes.LPCSTR, # szComponent : LPCSTR
ctypes.c_void_p, # piInstalled : INSTALLSTATE* in/out
ctypes.c_void_p, # piAction : INSTALLSTATE* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetComponentStateA = Fiddle::Function.new(
lib['MsiGetComponentStateA'],
[
-Fiddle::TYPE_INT, # hInstall : MSIHANDLE
Fiddle::TYPE_VOIDP, # szComponent : LPCSTR
Fiddle::TYPE_VOIDP, # piInstalled : INSTALLSTATE* in/out
Fiddle::TYPE_VOIDP, # piAction : INSTALLSTATE* in/out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetComponentStateA(
hInstall: u32, // MSIHANDLE
szComponent: *const u8, // LPCSTR
piInstalled: *mut i32, // INSTALLSTATE* in/out
piAction: *mut i32 // INSTALLSTATE* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiGetComponentStateA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szComponent, ref int piInstalled, ref int piAction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetComponentStateA' -Namespace Win32 -PassThru
# $api::MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction)#uselib "msi.dll"
#func global MsiGetComponentStateA "MsiGetComponentStateA" sptr, sptr, sptr, sptr
; MsiGetComponentStateA hInstall, szComponent, varptr(piInstalled), varptr(piAction) ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szComponent : LPCSTR -> "sptr"
; piInstalled : INSTALLSTATE* in/out -> "sptr"
; piAction : INSTALLSTATE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "msi.dll" #cfunc global MsiGetComponentStateA "MsiGetComponentStateA" int, str, var, var ; res = MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction) ; hInstall : MSIHANDLE -> "int" ; szComponent : LPCSTR -> "str" ; piInstalled : INSTALLSTATE* in/out -> "var" ; piAction : INSTALLSTATE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetComponentStateA "MsiGetComponentStateA" int, str, sptr, sptr ; res = MsiGetComponentStateA(hInstall, szComponent, varptr(piInstalled), varptr(piAction)) ; hInstall : MSIHANDLE -> "int" ; szComponent : LPCSTR -> "str" ; piInstalled : INSTALLSTATE* in/out -> "sptr" ; piAction : INSTALLSTATE* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent, INSTALLSTATE* piInstalled, INSTALLSTATE* piAction) #uselib "msi.dll" #cfunc global MsiGetComponentStateA "MsiGetComponentStateA" int, str, var, var ; res = MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction) ; hInstall : MSIHANDLE -> "int" ; szComponent : LPCSTR -> "str" ; piInstalled : INSTALLSTATE* in/out -> "var" ; piAction : INSTALLSTATE* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent, INSTALLSTATE* piInstalled, INSTALLSTATE* piAction) #uselib "msi.dll" #cfunc global MsiGetComponentStateA "MsiGetComponentStateA" int, str, intptr, intptr ; res = MsiGetComponentStateA(hInstall, szComponent, varptr(piInstalled), varptr(piAction)) ; hInstall : MSIHANDLE -> "int" ; szComponent : LPCSTR -> "str" ; piInstalled : INSTALLSTATE* in/out -> "intptr" ; piAction : INSTALLSTATE* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetComponentStateA = msi.NewProc("MsiGetComponentStateA")
)
// hInstall (MSIHANDLE), szComponent (LPCSTR), piInstalled (INSTALLSTATE* in/out), piAction (INSTALLSTATE* in/out)
r1, _, err := procMsiGetComponentStateA.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szComponent))),
uintptr(piInstalled),
uintptr(piAction),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetComponentStateA(
hInstall: DWORD; // MSIHANDLE
szComponent: PAnsiChar; // LPCSTR
piInstalled: Pointer; // INSTALLSTATE* in/out
piAction: Pointer // INSTALLSTATE* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetComponentStateA';result := DllCall("msi\MsiGetComponentStateA"
, "UInt", hInstall ; MSIHANDLE
, "AStr", szComponent ; LPCSTR
, "Ptr", piInstalled ; INSTALLSTATE* in/out
, "Ptr", piAction ; INSTALLSTATE* in/out
, "UInt") ; return: DWORD●MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction) = DLL("msi.dll", "dword MsiGetComponentStateA(dword, char*, void*, void*)")
# 呼び出し: MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction)
# hInstall : MSIHANDLE -> "dword"
# szComponent : LPCSTR -> "char*"
# piInstalled : INSTALLSTATE* in/out -> "void*"
# piAction : INSTALLSTATE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetComponentStateA(
hInstall: u32, // MSIHANDLE
szComponent: [*c]const u8, // LPCSTR
piInstalled: [*c]i32, // INSTALLSTATE* in/out
piAction: [*c]i32 // INSTALLSTATE* in/out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetComponentStateA(
hInstall: uint32, # MSIHANDLE
szComponent: cstring, # LPCSTR
piInstalled: ptr int32, # INSTALLSTATE* in/out
piAction: ptr int32 # INSTALLSTATE* in/out
): uint32 {.importc: "MsiGetComponentStateA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetComponentStateA(
uint hInstall, // MSIHANDLE
const(char)* szComponent, // LPCSTR
int* piInstalled, // INSTALLSTATE* in/out
int* piAction // INSTALLSTATE* in/out
);ccall((:MsiGetComponentStateA, "msi.dll"), stdcall, UInt32,
(UInt32, Cstring, Ptr{Int32}, Ptr{Int32}),
hInstall, szComponent, piInstalled, piAction)
# hInstall : MSIHANDLE -> UInt32
# szComponent : LPCSTR -> Cstring
# piInstalled : INSTALLSTATE* in/out -> Ptr{Int32}
# piAction : INSTALLSTATE* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetComponentStateA(
uint32_t hInstall,
const char* szComponent,
int32_t* piInstalled,
int32_t* piAction);
]]
local msi = ffi.load("msi")
-- msi.MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction)
-- hInstall : MSIHANDLE
-- szComponent : LPCSTR
-- piInstalled : INSTALLSTATE* in/out
-- piAction : INSTALLSTATE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetComponentStateA = lib.func('__stdcall', 'MsiGetComponentStateA', 'uint32_t', ['uint32_t', 'str', 'int32_t *', 'int32_t *']);
// MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction)
// hInstall : MSIHANDLE -> 'uint32_t'
// szComponent : LPCSTR -> 'str'
// piInstalled : INSTALLSTATE* in/out -> 'int32_t *'
// piAction : INSTALLSTATE* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetComponentStateA: { parameters: ["u32", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction)
// hInstall : MSIHANDLE -> "u32"
// szComponent : LPCSTR -> "buffer"
// piInstalled : INSTALLSTATE* in/out -> "pointer"
// piAction : INSTALLSTATE* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetComponentStateA(
uint32_t hInstall,
const char* szComponent,
int32_t* piInstalled,
int32_t* piAction);
C, "msi.dll");
// $ffi->MsiGetComponentStateA(hInstall, szComponent, piInstalled, piAction);
// hInstall : MSIHANDLE
// szComponent : LPCSTR
// piInstalled : INSTALLSTATE* in/out
// piAction : INSTALLSTATE* 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 Msi extends StdCallLibrary {
Msi INSTANCE = Native.load("msi", Msi.class, W32APIOptions.ASCII_OPTIONS);
int MsiGetComponentStateA(
int hInstall, // MSIHANDLE
String szComponent, // LPCSTR
IntByReference piInstalled, // INSTALLSTATE* in/out
IntByReference piAction // INSTALLSTATE* in/out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetComponentStateA = MsiGetComponentStateA(
hInstall : UInt32, # MSIHANDLE
szComponent : UInt8*, # LPCSTR
piInstalled : Int32*, # INSTALLSTATE* in/out
piAction : Int32* # INSTALLSTATE* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetComponentStateANative = Uint32 Function(Uint32, Pointer<Utf8>, Pointer<Int32>, Pointer<Int32>);
typedef MsiGetComponentStateADart = int Function(int, Pointer<Utf8>, Pointer<Int32>, Pointer<Int32>);
final MsiGetComponentStateA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetComponentStateANative, MsiGetComponentStateADart>('MsiGetComponentStateA');
// hInstall : MSIHANDLE -> Uint32
// szComponent : LPCSTR -> Pointer<Utf8>
// piInstalled : INSTALLSTATE* in/out -> Pointer<Int32>
// piAction : INSTALLSTATE* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetComponentStateA(
hInstall: DWORD; // MSIHANDLE
szComponent: PAnsiChar; // LPCSTR
piInstalled: Pointer; // INSTALLSTATE* in/out
piAction: Pointer // INSTALLSTATE* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetComponentStateA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetComponentStateA"
c_MsiGetComponentStateA :: Word32 -> CString -> Ptr Int32 -> Ptr Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szComponent : LPCSTR -> CString
-- piInstalled : INSTALLSTATE* in/out -> Ptr Int32
-- piAction : INSTALLSTATE* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetcomponentstatea =
foreign "MsiGetComponentStateA"
(uint32_t @-> string @-> (ptr int32_t) @-> (ptr int32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szComponent : LPCSTR -> string *)
(* piInstalled : INSTALLSTATE* in/out -> (ptr int32_t) *)
(* piAction : INSTALLSTATE* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetComponentStateA" msi-get-component-state-a :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-component :string) ; LPCSTR
(pi-installed :pointer) ; INSTALLSTATE* in/out
(pi-action :pointer)) ; INSTALLSTATE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetComponentStateA = Win32::API::More->new('msi',
'DWORD MsiGetComponentStateA(DWORD hInstall, LPCSTR szComponent, LPVOID piInstalled, LPVOID piAction)');
# my $ret = $MsiGetComponentStateA->Call($hInstall, $szComponent, $piInstalled, $piAction);
# hInstall : MSIHANDLE -> DWORD
# szComponent : LPCSTR -> LPCSTR
# piInstalled : INSTALLSTATE* in/out -> LPVOID
# piAction : INSTALLSTATE* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f MsiGetComponentStateW (Unicode版) — コンポーネントの現在の状態と要求された状態を取得する(Unicode版)。
使用する型