ホーム › System.ApplicationInstallationAndServicing › MsiQueryComponentStateW
MsiQueryComponentStateW
関数指定したコンポーネントのインストール状態を問い合わせて取得する。
シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiQueryComponentStateW(
LPCWSTR szProductCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
LPCWSTR szComponentCode,
INSTALLSTATE* pdwState // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| szProductCode | LPCWSTR | in |
| szUserSid | LPCWSTR | inoptional |
| dwContext | MSIINSTALLCONTEXT | in |
| szComponentCode | LPCWSTR | in |
| pdwState | INSTALLSTATE* | outoptional |
戻り値の型: DWORD
各言語での呼び出し定義
// 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, 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, int
; res = MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szComponentCode : LPCWSTR -> "wstr"
; pdwState : INSTALLSTATE* optional, out -> "int"; DWORD MsiQueryComponentStateW(LPCWSTR szProductCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCWSTR szComponentCode, INSTALLSTATE* pdwState)
#uselib "msi.dll"
#cfunc global MsiQueryComponentStateW "MsiQueryComponentStateW" wstr, wstr, int, wstr, int
; res = MsiQueryComponentStateW(szProductCode, szUserSid, dwContext, szComponentCode, pdwState)
; szProductCode : LPCWSTR -> "wstr"
; szUserSid : LPCWSTR optional -> "wstr"
; dwContext : MSIINSTALLCONTEXT -> "int"
; szComponentCode : LPCWSTR -> "wstr"
; pdwState : INSTALLSTATE* optional, out -> "int"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 // DWORDfunction 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 版の利用を推奨。