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

MsiGetComponentPathA

関数
製品とコンポーネントを指定してインストール済みパスと状態を取得する。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (ANSI / -A)
#include <windows.h>

INSTALLSTATE MsiGetComponentPathA(
    LPCSTR szProduct,
    LPCSTR szComponent,
    LPSTR lpPathBuf,   // optional
    DWORD* pcchBuf   // optional
);

パラメーター

名前方向
szProductLPCSTRin
szComponentLPCSTRin
lpPathBufLPSTRoutoptional
pcchBufDWORD*inoutoptional

戻り値の型: INSTALLSTATE

各言語での呼び出し定義

// msi.dll  (ANSI / -A)
#include <windows.h>

INSTALLSTATE MsiGetComponentPathA(
    LPCSTR szProduct,
    LPCSTR szComponent,
    LPSTR lpPathBuf,   // optional
    DWORD* pcchBuf   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int MsiGetComponentPathA(
    [MarshalAs(UnmanagedType.LPStr)] string szProduct,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string szComponent,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpPathBuf,   // LPSTR optional, out
    IntPtr pcchBuf   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetComponentPathA(
    <MarshalAs(UnmanagedType.LPStr)> szProduct As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> szComponent As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> lpPathBuf As System.Text.StringBuilder,   ' LPSTR optional, out
    pcchBuf As IntPtr   ' DWORD* optional, in/out
) As Integer
End Function
' szProduct : LPCSTR
' szComponent : LPCSTR
' lpPathBuf : LPSTR optional, out
' pcchBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetComponentPathA Lib "msi" ( _
    ByVal szProduct As String, _
    ByVal szComponent As String, _
    ByVal lpPathBuf As String, _
    ByVal pcchBuf As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiGetComponentPathA = ctypes.windll.msi.MsiGetComponentPathA
MsiGetComponentPathA.restype = ctypes.c_int
MsiGetComponentPathA.argtypes = [
    wintypes.LPCSTR,  # szProduct : LPCSTR
    wintypes.LPCSTR,  # szComponent : LPCSTR
    wintypes.LPSTR,  # lpPathBuf : LPSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchBuf : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetComponentPathA = Fiddle::Function.new(
  lib['MsiGetComponentPathA'],
  [
    Fiddle::TYPE_VOIDP,  # szProduct : LPCSTR
    Fiddle::TYPE_VOIDP,  # szComponent : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpPathBuf : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchBuf : DWORD* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "msi")]
extern "system" {
    fn MsiGetComponentPathA(
        szProduct: *const u8,  // LPCSTR
        szComponent: *const u8,  // LPCSTR
        lpPathBuf: *mut u8,  // LPSTR optional, out
        pcchBuf: *mut u32  // DWORD* optional, in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern int MsiGetComponentPathA([MarshalAs(UnmanagedType.LPStr)] string szProduct, [MarshalAs(UnmanagedType.LPStr)] string szComponent, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpPathBuf, IntPtr pcchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetComponentPathA' -Namespace Win32 -PassThru
# $api::MsiGetComponentPathA(szProduct, szComponent, lpPathBuf, pcchBuf)
#uselib "msi.dll"
#func global MsiGetComponentPathA "MsiGetComponentPathA" sptr, sptr, sptr, sptr
; MsiGetComponentPathA szProduct, szComponent, varptr(lpPathBuf), varptr(pcchBuf)   ; 戻り値は stat
; szProduct : LPCSTR -> "sptr"
; szComponent : LPCSTR -> "sptr"
; lpPathBuf : LPSTR optional, out -> "sptr"
; pcchBuf : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetComponentPathA "MsiGetComponentPathA" str, str, var, var
; res = MsiGetComponentPathA(szProduct, szComponent, lpPathBuf, pcchBuf)
; szProduct : LPCSTR -> "str"
; szComponent : LPCSTR -> "str"
; lpPathBuf : LPSTR optional, out -> "var"
; pcchBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INSTALLSTATE MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent, LPSTR lpPathBuf, DWORD* pcchBuf)
#uselib "msi.dll"
#cfunc global MsiGetComponentPathA "MsiGetComponentPathA" str, str, var, var
; res = MsiGetComponentPathA(szProduct, szComponent, lpPathBuf, pcchBuf)
; szProduct : LPCSTR -> "str"
; szComponent : LPCSTR -> "str"
; lpPathBuf : LPSTR optional, out -> "var"
; pcchBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetComponentPathA = msi.NewProc("MsiGetComponentPathA")
)

// szProduct (LPCSTR), szComponent (LPCSTR), lpPathBuf (LPSTR optional, out), pcchBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetComponentPathA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szProduct))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szComponent))),
	uintptr(lpPathBuf),
	uintptr(pcchBuf),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INSTALLSTATE
function MsiGetComponentPathA(
  szProduct: PAnsiChar;   // LPCSTR
  szComponent: PAnsiChar;   // LPCSTR
  lpPathBuf: PAnsiChar;   // LPSTR optional, out
  pcchBuf: Pointer   // DWORD* optional, in/out
): Integer; stdcall;
  external 'msi.dll' name 'MsiGetComponentPathA';
result := DllCall("msi\MsiGetComponentPathA"
    , "AStr", szProduct   ; LPCSTR
    , "AStr", szComponent   ; LPCSTR
    , "Ptr", lpPathBuf   ; LPSTR optional, out
    , "Ptr", pcchBuf   ; DWORD* optional, in/out
    , "Int")   ; return: INSTALLSTATE
●MsiGetComponentPathA(szProduct, szComponent, lpPathBuf, pcchBuf) = DLL("msi.dll", "int MsiGetComponentPathA(char*, char*, char*, void*)")
# 呼び出し: MsiGetComponentPathA(szProduct, szComponent, lpPathBuf, pcchBuf)
# szProduct : LPCSTR -> "char*"
# szComponent : LPCSTR -> "char*"
# lpPathBuf : LPSTR optional, out -> "char*"
# pcchBuf : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。