MsiGetComponentPathW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
INSTALLSTATE MsiGetComponentPathW(
LPCWSTR szProduct,
LPCWSTR szComponent,
LPWSTR lpPathBuf, // optional
DWORD* pcchBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szProduct | LPCWSTR | in | クライアント製品の製品コードを指定します。 | ||||||||||
| szComponent | LPCWSTR | in | 位置を特定するコンポーネントのコンポーネント ID を指定します。 | ||||||||||
| lpPathBuf | LPWSTR | outoptional | コンポーネントへのパスを受け取る変数へのポインターです。このパラメーターは null を指定できます。コンポーネントがレジストリキーである場合、レジストリのルートは数値で表されます。これがレジストリサブキーのパスである場合は、キーパスの末尾にバックスラッシュが付きます。レジストリ値のキーパスである場合は、末尾にバックスラッシュは付きません。たとえば、32 ビットオペレーティングシステム上のレジストリパス HKEY_CURRENT_USER\SOFTWARE\Microsoft は、"01:\SOFTWARE\Microsoft" として返されます。32 ビットオペレーティングシステムで返されるレジストリのルートは、次の表のとおり定義されています。 注意 64 ビットオペレーティングシステムでは、この表の数値レジストリルートに 20 が加算され、32 ビットオペレーティングシステム上のレジストリキーパスと区別されます。
たとえば、コンポーネントパスが 64 ビットオペレーティングシステム上のレジストリキーである場合、レジストリキーパス HKEY_CURRENT_USER\SOFTWARE\Microsoft は "21:\SOFTWARE\Microsoft\" として返されます。
| ||||||||||
| pcchBuf | DWORD* | inoutoptional | lpPathBuf パラメーターが指すバッファーのサイズ(文字数)を指定する変数へのポインターです。入力時には、これは終端の null 文字用のスペースを含むバッファーの全サイズです。渡されたバッファーが小さすぎる場合、返されるカウントには終端の null 文字は含まれません。 lpPathBuf が null の場合、pcchBuf も null を指定できます。 |
戻り値の型: INSTALLSTATE
公式ドキュメント
MsiGetComponentPath 関数は、インストール済みコンポーネントへのフルパスを返します。コンポーネントのキーパスがレジストリキーである場合は、そのレジストリキーが返されます。(Unicode)
戻り値
MsiGetComponentPath 関数は次の値を返します。
| 値 | 意味 |
|---|---|
| 要求されたコンポーネントはコンピューター上で無効になっています。 | |
| コンポーネントはインストールされていません。 | |
| 関数のパラメーターのいずれかが無効です。 | |
| コンポーネントはローカルにインストールされています。 | |
| コンポーネントはソースから実行するようにインストールされています。 | |
| コンポーネントのソースにアクセスできません。 | |
| 製品コードまたはコンポーネント ID が不明です。 |
解説(Remarks)
MsiGetComponentPath 関数が成功すると、pcchBuf パラメーターには lpPathBuf 内の文字列の長さが格納されます。
MsiGetComponentPath 関数は、次の理由により INSTALLSTATE_ABSENT または INSTALL_STATE_UNKNOWN を返す場合があります。
- INSTALLSTATE_ABSENT
アプリケーションが MsiUseFeature を呼び出し、必要に応じて MsiConfigureFeature を呼び出すことで、機能がインストールされていることを適切に確認していませんでした。
- INSTALLSTATE_UNKNOWN
機能が公開されていません。アプリケーションは、これより前に MsiQueryFeatureState または MsiEnumFeatures を呼び出してこれを判別しておくべきでした。アプリケーションは初期化時にこれらの呼び出しを行います。アプリケーションは、公開されていることが判明している機能のみを使用すべきです。INSTALLSTATE_UNKNOWN は MsiUseFeature からも返されているはずなので、 MsiUseFeature が呼び出されていないか、その戻り値が適切にチェックされていません。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetComponentPath を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
INSTALLSTATE MsiGetComponentPathW(
LPCWSTR szProduct,
LPCWSTR szComponent,
LPWSTR lpPathBuf, // optional
DWORD* pcchBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int MsiGetComponentPathW(
[MarshalAs(UnmanagedType.LPWStr)] string szProduct, // LPCWSTR
[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 MsiGetComponentPathW(
<MarshalAs(UnmanagedType.LPWStr)> szProduct As String, ' LPCWSTR
<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' szProduct : LPCWSTR
' szComponent : LPCWSTR
' lpPathBuf : LPWSTR optional, out
' pcchBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetComponentPathW Lib "msi" ( _
ByVal szProduct As LongPtr, _
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
MsiGetComponentPathW = ctypes.windll.msi.MsiGetComponentPathW
MsiGetComponentPathW.restype = ctypes.c_int
MsiGetComponentPathW.argtypes = [
wintypes.LPCWSTR, # szProduct : LPCWSTR
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')
MsiGetComponentPathW = Fiddle::Function.new(
lib['MsiGetComponentPathW'],
[
Fiddle::TYPE_VOIDP, # szProduct : LPCWSTR
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 MsiGetComponentPathW(
szProduct: *const u16, // LPCWSTR
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 MsiGetComponentPathW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] string szComponent, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf, IntPtr pcchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetComponentPathW' -Namespace Win32 -PassThru
# $api::MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf)#uselib "msi.dll"
#func global MsiGetComponentPathW "MsiGetComponentPathW" wptr, wptr, wptr, wptr
; MsiGetComponentPathW szProduct, szComponent, varptr(lpPathBuf), varptr(pcchBuf) ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; szComponent : LPCWSTR -> "wptr"
; lpPathBuf : LPWSTR optional, out -> "wptr"
; pcchBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetComponentPathW "MsiGetComponentPathW" wstr, wstr, var, var ; res = MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf) ; szProduct : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetComponentPathW "MsiGetComponentPathW" wstr, wstr, sptr, sptr ; res = MsiGetComponentPathW(szProduct, szComponent, varptr(lpPathBuf), varptr(pcchBuf)) ; szProduct : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; lpPathBuf : LPWSTR optional, out -> "sptr" ; pcchBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INSTALLSTATE MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent, LPWSTR lpPathBuf, DWORD* pcchBuf) #uselib "msi.dll" #cfunc global MsiGetComponentPathW "MsiGetComponentPathW" wstr, wstr, var, var ; res = MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf) ; szProduct : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INSTALLSTATE MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent, LPWSTR lpPathBuf, DWORD* pcchBuf) #uselib "msi.dll" #cfunc global MsiGetComponentPathW "MsiGetComponentPathW" wstr, wstr, intptr, intptr ; res = MsiGetComponentPathW(szProduct, szComponent, varptr(lpPathBuf), varptr(pcchBuf)) ; szProduct : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; lpPathBuf : LPWSTR optional, out -> "intptr" ; pcchBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetComponentPathW = msi.NewProc("MsiGetComponentPathW")
)
// szProduct (LPCWSTR), szComponent (LPCWSTR), lpPathBuf (LPWSTR optional, out), pcchBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetComponentPathW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProduct))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
uintptr(lpPathBuf),
uintptr(pcchBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INSTALLSTATEfunction MsiGetComponentPathW(
szProduct: PWideChar; // LPCWSTR
szComponent: PWideChar; // LPCWSTR
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchBuf: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'msi.dll' name 'MsiGetComponentPathW';result := DllCall("msi\MsiGetComponentPathW"
, "WStr", szProduct ; LPCWSTR
, "WStr", szComponent ; LPCWSTR
, "Ptr", lpPathBuf ; LPWSTR optional, out
, "Ptr", pcchBuf ; DWORD* optional, in/out
, "Int") ; return: INSTALLSTATE●MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf) = DLL("msi.dll", "int MsiGetComponentPathW(char*, char*, char*, void*)")
# 呼び出し: MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf)
# szProduct : LPCWSTR -> "char*"
# 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 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetComponentPathW(
szProduct: [*c]const u16, // LPCWSTR
szComponent: [*c]const u16, // LPCWSTR
lpPathBuf: [*c]u16, // LPWSTR optional, out
pcchBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetComponentPathW(
szProduct: WideCString, # LPCWSTR
szComponent: WideCString, # LPCWSTR
lpPathBuf: ptr uint16, # LPWSTR optional, out
pcchBuf: ptr uint32 # DWORD* optional, in/out
): int32 {.importc: "MsiGetComponentPathW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
int MsiGetComponentPathW(
const(wchar)* szProduct, // LPCWSTR
const(wchar)* szComponent, // LPCWSTR
wchar* lpPathBuf, // LPWSTR optional, out
uint* pcchBuf // DWORD* optional, in/out
);ccall((:MsiGetComponentPathW, "msi.dll"), stdcall, Int32,
(Cwstring, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
szProduct, szComponent, lpPathBuf, pcchBuf)
# szProduct : LPCWSTR -> Cwstring
# szComponent : LPCWSTR -> Cwstring
# lpPathBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t MsiGetComponentPathW(
const uint16_t* szProduct,
const uint16_t* szComponent,
uint16_t* lpPathBuf,
uint32_t* pcchBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf)
-- szProduct : LPCWSTR
-- szComponent : LPCWSTR
-- lpPathBuf : LPWSTR optional, out
-- pcchBuf : DWORD* optional, in/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 MsiGetComponentPathW = lib.func('__stdcall', 'MsiGetComponentPathW', 'int32_t', ['str16', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf)
// szProduct : LPCWSTR -> 'str16'
// szComponent : LPCWSTR -> 'str16'
// lpPathBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetComponentPathW: { parameters: ["buffer", "buffer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf)
// szProduct : LPCWSTR -> "buffer"
// szComponent : LPCWSTR -> "buffer"
// lpPathBuf : LPWSTR optional, out -> "buffer"
// pcchBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MsiGetComponentPathW(
const uint16_t* szProduct,
const uint16_t* szComponent,
uint16_t* lpPathBuf,
uint32_t* pcchBuf);
C, "msi.dll");
// $ffi->MsiGetComponentPathW(szProduct, szComponent, lpPathBuf, pcchBuf);
// szProduct : LPCWSTR
// szComponent : LPCWSTR
// lpPathBuf : LPWSTR optional, out
// pcchBuf : DWORD* optional, in/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 MsiGetComponentPathW(
WString szProduct, // LPCWSTR
WString szComponent, // LPCWSTR
char[] lpPathBuf, // LPWSTR optional, out
IntByReference pcchBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetComponentPathW = MsiGetComponentPathW(
szProduct : UInt16*, # LPCWSTR
szComponent : UInt16*, # LPCWSTR
lpPathBuf : UInt16*, # LPWSTR optional, out
pcchBuf : UInt32* # DWORD* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiGetComponentPathWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetComponentPathWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetComponentPathW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetComponentPathWNative, MsiGetComponentPathWDart>('MsiGetComponentPathW');
// szProduct : LPCWSTR -> Pointer<Utf16>
// szComponent : LPCWSTR -> Pointer<Utf16>
// lpPathBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetComponentPathW(
szProduct: PWideChar; // LPCWSTR
szComponent: PWideChar; // LPCWSTR
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchBuf: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'msi.dll' name 'MsiGetComponentPathW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetComponentPathW"
c_MsiGetComponentPathW :: CWString -> CWString -> CWString -> Ptr Word32 -> IO Int32
-- szProduct : LPCWSTR -> CWString
-- szComponent : LPCWSTR -> CWString
-- lpPathBuf : LPWSTR optional, out -> CWString
-- pcchBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetcomponentpathw =
foreign "MsiGetComponentPathW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning int32_t)
(* szProduct : LPCWSTR -> (ptr uint16_t) *)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* lpPathBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchBuf : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetComponentPathW" msi-get-component-path-w :convention :stdcall) :int32
(sz-product (:string :encoding :utf-16le)) ; LPCWSTR
(sz-component (:string :encoding :utf-16le)) ; LPCWSTR
(lp-path-buf :pointer) ; LPWSTR optional, out
(pcch-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetComponentPathW = Win32::API::More->new('msi',
'int MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent, LPWSTR lpPathBuf, LPVOID pcchBuf)');
# my $ret = $MsiGetComponentPathW->Call($szProduct, $szComponent, $lpPathBuf, $pcchBuf);
# szProduct : LPCWSTR -> LPCWSTR
# szComponent : LPCWSTR -> LPCWSTR
# lpPathBuf : LPWSTR optional, out -> LPWSTR
# pcchBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiGetComponentPathA (ANSI版) — 製品とコンポーネントを指定してインストール済みパスと状態を取得する。
- f MsiGetComponentPathExW — インストールコンテキストとユーザーSIDを指定してコンポーネントのパスと状態を取得する。