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
);

パラメーター

名前方向
hInstallMSIHANDLEin
szComponentLPCWSTRin
piInstalledINSTALLSTATE*inout
piActionINSTALLSTATE*inout

戻り値の型: DWORD

各言語での呼び出し定義

// 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, piInstalled, 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, int, int
; res = MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCWSTR -> "wstr"
; piInstalled : INSTALLSTATE* in/out -> "int"
; piAction : INSTALLSTATE* in/out -> "int"
; DWORD MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent, INSTALLSTATE* piInstalled, INSTALLSTATE* piAction)
#uselib "msi.dll"
#cfunc global MsiGetComponentStateW "MsiGetComponentStateW" int, wstr, int, int
; res = MsiGetComponentStateW(hInstall, szComponent, piInstalled, piAction)
; hInstall : MSIHANDLE -> "int"
; szComponent : LPCWSTR -> "wstr"
; piInstalled : INSTALLSTATE* in/out -> "int"
; piAction : INSTALLSTATE* in/out -> "int"
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 版の利用を推奨。