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

MsiQueryComponentStateW

関数
指定したコンポーネントのインストール状態を問い合わせて取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiQueryComponentStateW(
    LPCWSTR szProductCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    LPCWSTR szComponentCode,
    INSTALLSTATE* pdwState   // optional
);

パラメーター

名前方向説明
szProductCodeLPCWSTRinコンポーネントを含む製品の ProductCode GUID を指定します。
szUserSidLPCWSTRinoptional

照会対象の製品インスタンスが存在するアカウントのセキュリティ識別子 (SID) を指定します。dwContextMSIINSTALLCONTEXT_MACHINE でない場合、null は現在のユーザーを指定します。

SID の種類 意味
NULL
NULL は現在ログオンしているユーザーを表します。
User SID
システム内の特定のユーザーに対する列挙を指定します。ユーザー SID の例としては "S-1-3-64-2415071341-1358098788-3127455600-2561" があります。
注意 特殊な SID 文字列 "S-1-5-18" (system) は、コンピューター単位 (per-machine) でインストールされた製品の列挙には使用できません。dwContextMSIINSTALLCONTEXT_MACHINE の場合、szUserSid は null でなければなりません。
dwContextMSIINSTALLCONTEXTin

照会対象の製品インスタンスのインストール コンテキストです。

名前 意味
MSIINSTALLCONTEXT_USERMANAGED
製品のユーザー単位の管理対象 (per-user-managed) インスタンスについて、コンポーネントの状態を取得します。
MSIINSTALLCONTEXT_USERUNMANAGED
製品のユーザー単位の非管理対象 (per-user-non-managed) インスタンスについて、コンポーネントの状態を取得します。
MSIINSTALLCONTEXT_MACHINE
製品のコンピューター単位 (per-machine) インスタンスについて、コンポーネントの状態を取得します。
szComponentCodeLPCWSTRin照会対象のコンポーネントを指定します。Component テーブルの ComponentID 列に記載されている、コンポーネントのコンポーネント コード GUID です。
pdwStateINSTALLSTATE*outoptional

指定した製品インスタンスにおけるコンポーネントのインストール状態です。このパラメーターは、次のいずれかの値または null 値を返すことがあります。

意味
INSTALLSTATE_LOCAL
コンポーネントはローカルにインストールされています。
INSTALLSTATE_SOURCE
コンポーネントはソースから実行するようにインストールされています。

戻り値の型: DWORD

公式ドキュメント

MsiQueryComponentState 関数は、コンポーネントのインストール状態を返します。(Unicode)

戻り値

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

意味
ERROR_ACCESS_DENIED
現在のユーザー以外のユーザーに対してインストールされた製品の情報を取得するには、呼び出し元プロセスに管理者権限が必要です。
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_SUCCESS
関数は正常に完了しました。
ERROR_UNKNOWN_COMPONENT
コンポーネント ID が既知のコンポーネントを識別しません。
ERROR_UNKNOWN_PRODUCT
製品コードが既知の製品を識別しません。
ERROR_FUNCTION_FAILED
いずれの Windows エラー コードにも分類できない失敗です。
ERROR_MORE_DATA
ユーザー SID を取得するにはバッファーが小さすぎます。

詳細については、 Displayed Error Messages を参照してください。

解説(Remarks)

メモ

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

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 MsiQueryComponentStateW(
    LPCWSTR szProductCode,
    LPCWSTR szUserSid,   // optional
    MSIINSTALLCONTEXT dwContext,
    LPCWSTR szComponentCode,
    INSTALLSTATE* pdwState   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiQueryComponentStateW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProductCode,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    [MarshalAs(UnmanagedType.LPWStr)] string szComponentCode,   // LPCWSTR
    IntPtr pdwState   // INSTALLSTATE* optional, out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiQueryComponentStateW(
    <MarshalAs(UnmanagedType.LPWStr)> szProductCode As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szUserSid As String,   ' LPCWSTR optional
    dwContext As Integer,   ' MSIINSTALLCONTEXT
    <MarshalAs(UnmanagedType.LPWStr)> szComponentCode As String,   ' LPCWSTR
    pdwState As IntPtr   ' INSTALLSTATE* optional, out
) As UInteger
End Function
' szProductCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' szComponentCode : LPCWSTR
' pdwState : INSTALLSTATE* optional, out
Declare PtrSafe Function MsiQueryComponentStateW Lib "msi" ( _
    ByVal szProductCode As LongPtr, _
    ByVal szUserSid As LongPtr, _
    ByVal dwContext As Long, _
    ByVal szComponentCode As LongPtr, _
    ByVal pdwState As LongPtr) 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

MsiQueryComponentStateW = ctypes.windll.msi.MsiQueryComponentStateW
MsiQueryComponentStateW.restype = wintypes.DWORD
MsiQueryComponentStateW.argtypes = [
    wintypes.LPCWSTR,  # szProductCode : LPCWSTR
    wintypes.LPCWSTR,  # szUserSid : LPCWSTR optional
    ctypes.c_int,  # dwContext : MSIINSTALLCONTEXT
    wintypes.LPCWSTR,  # szComponentCode : LPCWSTR
    ctypes.c_void_p,  # pdwState : INSTALLSTATE* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiQueryComponentStateW = Fiddle::Function.new(
  lib['MsiQueryComponentStateW'],
  [
    Fiddle::TYPE_VOIDP,  # szProductCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szUserSid : LPCWSTR optional
    Fiddle::TYPE_INT,  # dwContext : MSIINSTALLCONTEXT
    Fiddle::TYPE_VOIDP,  # szComponentCode : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pdwState : INSTALLSTATE* optional, out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiQueryComponentStateW(
        szProductCode: *const u16,  // LPCWSTR
        szUserSid: *const u16,  // LPCWSTR optional
        dwContext: i32,  // MSIINSTALLCONTEXT
        szComponentCode: *const u16,  // LPCWSTR
        pdwState: *mut i32  // INSTALLSTATE* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiQueryComponentStateW([MarshalAs(UnmanagedType.LPWStr)] string szProductCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, [MarshalAs(UnmanagedType.LPWStr)] string szComponentCode, IntPtr pdwState);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiQueryComponentStateW' -Namespace Win32 -PassThru
# $api::MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
#uselib "msi.dll"
#func global MsiQueryComponentStateW "MsiQueryComponentStateW" wptr, wptr, wptr, wptr, wptr
; MsiQueryComponentStateW szProductCode, szUserSid, dwContext, szComponentCode, varptr(pdwState)   ; 戻り値は stat
; szProductCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; szComponentCode : LPCWSTR -> "wptr"
; pdwState : INSTALLSTATE* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiQueryComponentStateW "MsiQueryComponentStateW" wstr, wstr, int, wstr, var
; res = MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szComponentCode : LPCWSTR -> "wstr"
; pdwState : INSTALLSTATE* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiQueryComponentStateW(LPCWSTR szProductCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCWSTR szComponentCode, INSTALLSTATE* pdwState)
#uselib "msi.dll"
#cfunc global MsiQueryComponentStateW "MsiQueryComponentStateW" wstr, wstr, int, wstr, var
; res = MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szComponentCode : LPCWSTR -> "wstr"
; pdwState : INSTALLSTATE* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiQueryComponentStateW = msi.NewProc("MsiQueryComponentStateW")
)

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

extern "msi" fn MsiQueryComponentStateW(
    szProductCode: [*c]const u16, // LPCWSTR
    szUserSid: [*c]const u16, // LPCWSTR optional
    dwContext: i32, // MSIINSTALLCONTEXT
    szComponentCode: [*c]const u16, // LPCWSTR
    pdwState: [*c]i32 // INSTALLSTATE* optional, out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiQueryComponentStateW(
    szProductCode: WideCString,  # LPCWSTR
    szUserSid: WideCString,  # LPCWSTR optional
    dwContext: int32,  # MSIINSTALLCONTEXT
    szComponentCode: WideCString,  # LPCWSTR
    pdwState: ptr int32  # INSTALLSTATE* optional, out
): uint32 {.importc: "MsiQueryComponentStateW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiQueryComponentStateW(
    const(wchar)* szProductCode,   // LPCWSTR
    const(wchar)* szUserSid,   // LPCWSTR optional
    int dwContext,   // MSIINSTALLCONTEXT
    const(wchar)* szComponentCode,   // LPCWSTR
    int* pdwState   // INSTALLSTATE* optional, out
);
ccall((:MsiQueryComponentStateW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Int32, Cwstring, Ptr{Int32}),
      szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
# szProductCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# szComponentCode : LPCWSTR -> Cwstring
# pdwState : INSTALLSTATE* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiQueryComponentStateW(
    const uint16_t* szProductCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    const uint16_t* szComponentCode,
    int32_t* pdwState);
]]
local msi = ffi.load("msi")
-- msi.MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
-- szProductCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- szComponentCode : LPCWSTR
-- pdwState : INSTALLSTATE* optional, 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 MsiQueryComponentStateW = lib.func('__stdcall', 'MsiQueryComponentStateW', 'uint32_t', ['str16', 'str16', 'int32_t', 'str16', 'int32_t *']);
// MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
// szProductCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// szComponentCode : LPCWSTR -> 'str16'
// pdwState : INSTALLSTATE* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiQueryComponentStateW: { parameters: ["buffer", "buffer", "i32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
// szProductCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// szComponentCode : LPCWSTR -> "buffer"
// pdwState : INSTALLSTATE* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiQueryComponentStateW(
    const uint16_t* szProductCode,
    const uint16_t* szUserSid,
    int32_t dwContext,
    const uint16_t* szComponentCode,
    int32_t* pdwState);
C, "msi.dll");
// $ffi->MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState);
// szProductCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// szComponentCode : LPCWSTR
// pdwState : INSTALLSTATE* optional, 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 MsiQueryComponentStateW(
        WString szProductCode,   // LPCWSTR
        WString szUserSid,   // LPCWSTR optional
        int dwContext,   // MSIINSTALLCONTEXT
        WString szComponentCode,   // LPCWSTR
        IntByReference pdwState   // INSTALLSTATE* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiQueryComponentStateW = MsiQueryComponentStateW(
    szProductCode : UInt16*,   # LPCWSTR
    szUserSid : UInt16*,   # LPCWSTR optional
    dwContext : Int32,   # MSIINSTALLCONTEXT
    szComponentCode : UInt16*,   # LPCWSTR
    pdwState : Int32*   # INSTALLSTATE* optional, out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiQueryComponentStateWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>, Pointer<Int32>);
typedef MsiQueryComponentStateWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Int32>);
final MsiQueryComponentStateW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiQueryComponentStateWNative, MsiQueryComponentStateWDart>('MsiQueryComponentStateW');
// szProductCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// szComponentCode : LPCWSTR -> Pointer<Utf16>
// pdwState : INSTALLSTATE* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiQueryComponentStateW(
  szProductCode: PWideChar;   // LPCWSTR
  szUserSid: PWideChar;   // LPCWSTR optional
  dwContext: Integer;   // MSIINSTALLCONTEXT
  szComponentCode: PWideChar;   // LPCWSTR
  pdwState: Pointer   // INSTALLSTATE* optional, out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiQueryComponentStateW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiQueryComponentStateW"
  c_MsiQueryComponentStateW :: CWString -> CWString -> Int32 -> CWString -> Ptr Int32 -> IO Word32
-- szProductCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- szComponentCode : LPCWSTR -> CWString
-- pdwState : INSTALLSTATE* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msiquerycomponentstatew =
  foreign "MsiQueryComponentStateW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> returning uint32_t)
(* szProductCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* szComponentCode : LPCWSTR -> (ptr uint16_t) *)
(* pdwState : INSTALLSTATE* optional, 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 ("MsiQueryComponentStateW" msi-query-component-state-w :convention :stdcall) :uint32
  (sz-product-code (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-user-sid (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-context :int32)   ; MSIINSTALLCONTEXT
  (sz-component-code (:string :encoding :utf-16le))   ; LPCWSTR
  (pdw-state :pointer))   ; INSTALLSTATE* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiQueryComponentStateW = Win32::API::More->new('msi',
    'DWORD MsiQueryComponentStateW(LPCWSTR szProductCode, LPCWSTR szUserSid, int dwContext, LPCWSTR szComponentCode, LPVOID pdwState)');
# my $ret = $MsiQueryComponentStateW->Call($szProductCode, $szUserSid, $dwContext, $szComponentCode, $pdwState);
# szProductCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# szComponentCode : LPCWSTR -> LPCWSTR
# pdwState : INSTALLSTATE* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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