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

MsiGetComponentStateW

関数
コンポーネントの現在の状態と要求された状態を取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiGetComponentStateW(
    MSIHANDLE hInstall,
    LPCWSTR szComponent,
    INSTALLSTATE* piInstalled,
    INSTALLSTATE* piAction
);

パラメーター

名前方向説明
hInstallMSIHANDLEinDLL カスタムアクションに渡された、または MsiOpenPackageMsiOpenPackageExMsiOpenProduct によって取得したインストールへのハンドルです。
szComponentLPCWSTRin製品内のコンポーネント名を指定する、null で終わる文字列です。
piInstalledINSTALLSTATE*inout

現在のインストール状態を受け取ります。このパラメーターを null にすることはできません。このパラメーターには次のいずれかの値を指定できます。

意味
INSTALLSTATE_ABSENT
コンポーネントはインストールされていません。
INSTALLSTATE_DEFAULT
コンポーネントは既定の場所(ローカルまたはソース)にインストールされています。
INSTALLSTATE_LOCAL
コンポーネントはローカルドライブにインストールされています。
INSTALLSTATE_REMOVED
コンポーネントは削除中です。アクション状態であり、設定はできません。
INSTALLSTATE_SOURCE
コンポーネントはソース、CD-ROM、またはネットワークから実行されます。
INSTALLSTATE_UNKNOWN
認識されない製品名または機能名が関数に渡されました。
piActionINSTALLSTATE*inoutインストール中に実行されるアクションを受け取ります。このパラメーターを null にすることはできません。戻り値については piInstalled を参照してください。

戻り値の型: DWORD

公式ドキュメント

MsiGetComponentState 関数は、コンポーネントの状態を取得します。(Unicode)

戻り値

MsiGetComponentState 関数は次の値を返します。

解説(Remarks)

関数が失敗した場合は、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。

詳細については、プログラムからのデータベース関数の呼び出しを参照してください。

メモ

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

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

各言語での呼び出し定義

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiGetComponentStateW(
    MSIHANDLE hInstall,
    LPCWSTR szComponent,
    INSTALLSTATE* piInstalled,
    INSTALLSTATE* piAction
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetComponentStateW(
    uint hInstall,   // MSIHANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string szComponent,   // LPCWSTR
    ref int piInstalled,   // INSTALLSTATE* in/out
    ref int piAction   // INSTALLSTATE* in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetComponentStateW(
    hInstall As UInteger,   ' MSIHANDLE
    <MarshalAs(UnmanagedType.LPWStr)> szComponent As String,   ' LPCWSTR
    ByRef piInstalled As Integer,   ' INSTALLSTATE* in/out
    ByRef piAction As Integer   ' INSTALLSTATE* in/out
) As UInteger
End Function
' hInstall : MSIHANDLE
' szComponent : LPCWSTR
' piInstalled : INSTALLSTATE* in/out
' piAction : INSTALLSTATE* in/out
Declare PtrSafe Function MsiGetComponentStateW Lib "msi" ( _
    ByVal hInstall As Long, _
    ByVal szComponent As LongPtr, _
    ByRef piInstalled As Long, _
    ByRef piAction As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiGetComponentStateW = ctypes.windll.msi.MsiGetComponentStateW
MsiGetComponentStateW.restype = wintypes.DWORD
MsiGetComponentStateW.argtypes = [
    wintypes.DWORD,  # hInstall : MSIHANDLE
    wintypes.LPCWSTR,  # szComponent : LPCWSTR
    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')
MsiGetComponentStateW = Fiddle::Function.new(
  lib['MsiGetComponentStateW'],
  [
    -Fiddle::TYPE_INT,  # hInstall : MSIHANDLE
    Fiddle::TYPE_VOIDP,  # szComponent : LPCWSTR
    Fiddle::TYPE_VOIDP,  # piInstalled : INSTALLSTATE* in/out
    Fiddle::TYPE_VOIDP,  # piAction : INSTALLSTATE* in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetComponentStateW(
        hInstall: u32,  // MSIHANDLE
        szComponent: *const u16,  // LPCWSTR
        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.Unicode)]
public static extern uint MsiGetComponentStateW(uint hInstall, [MarshalAs(UnmanagedType.LPWStr)] string szComponent, ref int piInstalled, ref int piAction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetComponentStateW' -Namespace Win32 -PassThru
# $api::MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
#uselib "msi.dll"
#func global MsiGetComponentStateW "MsiGetComponentStateW" wptr, wptr, wptr, wptr
; MsiGetComponentStateW hInstall, szComponent, varptr(piInstalled), varptr(piAction)   ; 戻り値は stat
; hInstall : MSIHANDLE -> "wptr"
; szComponent : LPCWSTR -> "wptr"
; piInstalled : INSTALLSTATE* in/out -> "wptr"
; piAction : INSTALLSTATE* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetComponentStateW "MsiGetComponentStateW" int, wstr, var, var
; res = MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCWSTR -> "wstr"
; piInstalled : INSTALLSTATE* in/out -> "var"
; piAction : INSTALLSTATE* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent, INSTALLSTATE* piInstalled, INSTALLSTATE* piAction)
#uselib "msi.dll"
#cfunc global MsiGetComponentStateW "MsiGetComponentStateW" int, wstr, var, var
; res = MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCWSTR -> "wstr"
; piInstalled : INSTALLSTATE* in/out -> "var"
; piAction : INSTALLSTATE* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetComponentStateW = msi.NewProc("MsiGetComponentStateW")
)

// hInstall (MSIHANDLE), szComponent (LPCWSTR), piInstalled (INSTALLSTATE* in/out), piAction (INSTALLSTATE* in/out)
r1, _, err := procMsiGetComponentStateW.Call(
	uintptr(hInstall),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
	uintptr(piInstalled),
	uintptr(piAction),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiGetComponentStateW(
  hInstall: DWORD;   // MSIHANDLE
  szComponent: PWideChar;   // LPCWSTR
  piInstalled: Pointer;   // INSTALLSTATE* in/out
  piAction: Pointer   // INSTALLSTATE* in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetComponentStateW';
result := DllCall("msi\MsiGetComponentStateW"
    , "UInt", hInstall   ; MSIHANDLE
    , "WStr", szComponent   ; LPCWSTR
    , "Ptr", piInstalled   ; INSTALLSTATE* in/out
    , "Ptr", piAction   ; INSTALLSTATE* in/out
    , "UInt")   ; return: DWORD
●MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction) = DLL("msi.dll", "dword MsiGetComponentStateW(dword, char*, void*, void*)")
# 呼び出し: MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
# hInstall : MSIHANDLE -> "dword"
# szComponent : LPCWSTR -> "char*"
# piInstalled : INSTALLSTATE* in/out -> "void*"
# piAction : INSTALLSTATE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "msi" fn MsiGetComponentStateW(
    hInstall: u32, // MSIHANDLE
    szComponent: [*c]const u16, // LPCWSTR
    piInstalled: [*c]i32, // INSTALLSTATE* in/out
    piAction: [*c]i32 // INSTALLSTATE* in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiGetComponentStateW(
    hInstall: uint32,  # MSIHANDLE
    szComponent: WideCString,  # LPCWSTR
    piInstalled: ptr int32,  # INSTALLSTATE* in/out
    piAction: ptr int32  # INSTALLSTATE* in/out
): uint32 {.importc: "MsiGetComponentStateW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiGetComponentStateW(
    uint hInstall,   // MSIHANDLE
    const(wchar)* szComponent,   // LPCWSTR
    int* piInstalled,   // INSTALLSTATE* in/out
    int* piAction   // INSTALLSTATE* in/out
);
ccall((:MsiGetComponentStateW, "msi.dll"), stdcall, UInt32,
      (UInt32, Cwstring, Ptr{Int32}, Ptr{Int32}),
      hInstall, szComponent, piInstalled, piAction)
# hInstall : MSIHANDLE -> UInt32
# szComponent : LPCWSTR -> Cwstring
# piInstalled : INSTALLSTATE* in/out -> Ptr{Int32}
# piAction : INSTALLSTATE* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetComponentStateW(
    uint32_t hInstall,
    const uint16_t* szComponent,
    int32_t* piInstalled,
    int32_t* piAction);
]]
local msi = ffi.load("msi")
-- msi.MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
-- hInstall : MSIHANDLE
-- szComponent : LPCWSTR
-- piInstalled : INSTALLSTATE* in/out
-- piAction : INSTALLSTATE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetComponentStateW = lib.func('__stdcall', 'MsiGetComponentStateW', 'uint32_t', ['uint32_t', 'str16', 'int32_t *', 'int32_t *']);
// MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
// hInstall : MSIHANDLE -> 'uint32_t'
// szComponent : LPCWSTR -> 'str16'
// piInstalled : INSTALLSTATE* in/out -> 'int32_t *'
// piAction : INSTALLSTATE* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiGetComponentStateW: { parameters: ["u32", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
// hInstall : MSIHANDLE -> "u32"
// szComponent : LPCWSTR -> "buffer"
// piInstalled : INSTALLSTATE* in/out -> "pointer"
// piAction : INSTALLSTATE* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetComponentStateW(
    uint32_t hInstall,
    const uint16_t* szComponent,
    int32_t* piInstalled,
    int32_t* piAction);
C, "msi.dll");
// $ffi->MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction);
// hInstall : MSIHANDLE
// szComponent : LPCWSTR
// 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.UNICODE_OPTIONS);
    int MsiGetComponentStateW(
        int hInstall,   // MSIHANDLE
        WString szComponent,   // LPCWSTR
        IntByReference piInstalled,   // INSTALLSTATE* in/out
        IntByReference piAction   // INSTALLSTATE* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiGetComponentStateW = MsiGetComponentStateW(
    hInstall : UInt32,   # MSIHANDLE
    szComponent : UInt16*,   # LPCWSTR
    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 MsiGetComponentStateWNative = Uint32 Function(Uint32, Pointer<Utf16>, Pointer<Int32>, Pointer<Int32>);
typedef MsiGetComponentStateWDart = int Function(int, Pointer<Utf16>, Pointer<Int32>, Pointer<Int32>);
final MsiGetComponentStateW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiGetComponentStateWNative, MsiGetComponentStateWDart>('MsiGetComponentStateW');
// hInstall : MSIHANDLE -> Uint32
// szComponent : LPCWSTR -> Pointer<Utf16>
// piInstalled : INSTALLSTATE* in/out -> Pointer<Int32>
// piAction : INSTALLSTATE* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiGetComponentStateW(
  hInstall: DWORD;   // MSIHANDLE
  szComponent: PWideChar;   // LPCWSTR
  piInstalled: Pointer;   // INSTALLSTATE* in/out
  piAction: Pointer   // INSTALLSTATE* in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetComponentStateW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiGetComponentStateW"
  c_MsiGetComponentStateW :: Word32 -> CWString -> Ptr Int32 -> Ptr Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szComponent : LPCWSTR -> CWString
-- piInstalled : INSTALLSTATE* in/out -> Ptr Int32
-- piAction : INSTALLSTATE* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msigetcomponentstatew =
  foreign "MsiGetComponentStateW"
    (uint32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr int32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* 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 ("MsiGetComponentStateW" msi-get-component-state-w :convention :stdcall) :uint32
  (h-install :uint32)   ; MSIHANDLE
  (sz-component (:string :encoding :utf-16le))   ; LPCWSTR
  (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 $MsiGetComponentStateW = Win32::API::More->new('msi',
    'DWORD MsiGetComponentStateW(DWORD hInstall, LPCWSTR szComponent, LPVOID piInstalled, LPVOID piAction)');
# my $ret = $MsiGetComponentStateW->Call($hInstall, $szComponent, $piInstalled, $piAction);
# hInstall : MSIHANDLE -> DWORD
# szComponent : LPCWSTR -> LPCWSTR
# piInstalled : INSTALLSTATE* in/out -> LPVOID
# piAction : INSTALLSTATE* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型