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

MsiLocateComponentW

関数
現在の製品コンテキストでコンポーネントのパスと状態を取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

INSTALLSTATE MsiLocateComponentW(
    LPCWSTR szComponent,
    LPWSTR lpPathBuf,   // optional
    DWORD* pcchBuf   // optional
);

パラメーター

名前方向
szComponentLPCWSTRin
lpPathBufLPWSTRoutoptional
pcchBufDWORD*inoutoptional

戻り値の型: INSTALLSTATE

各言語での呼び出し定義

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

INSTALLSTATE MsiLocateComponentW(
    LPCWSTR szComponent,
    LPWSTR lpPathBuf,   // optional
    DWORD* pcchBuf   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiLocateComponentW(
    [MarshalAs(UnmanagedType.LPWStr)] string szComponent,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf,   // LPWSTR optional, out
    IntPtr pcchBuf   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiLocateComponentW(
    <MarshalAs(UnmanagedType.LPWStr)> szComponent As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpPathBuf As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchBuf As IntPtr   ' DWORD* optional, in/out
) As Integer
End Function
' szComponent : LPCWSTR
' lpPathBuf : LPWSTR optional, out
' pcchBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiLocateComponentW Lib "msi" ( _
    ByVal szComponent As LongPtr, _
    ByVal lpPathBuf As LongPtr, _
    ByVal pcchBuf 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

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

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiLocateComponentW = msi.NewProc("MsiLocateComponentW")
)

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