MsiProvideComponentW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiProvideComponentW(
LPCWSTR szProduct,
LPCWSTR szFeature,
LPCWSTR szComponent,
DWORD dwInstallMode,
LPWSTR lpPathBuf, // optional
DWORD* pcchPathBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szProduct | LPCWSTR | in | 必要なコンポーネントを含む機能を持つ製品の製品コードを指定します。 | ||||||||||||
| szFeature | LPCWSTR | in | 必要なコンポーネントを含む機能の機能 ID を指定します。 | ||||||||||||
| szComponent | LPCWSTR | in | 必要なコンポーネントのコンポーネントコードを指定します。 | ||||||||||||
| dwInstallMode | DWORD | in | インストールモードを定義します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| lpPathBuf | LPWSTR | outoptional | コンポーネントへのパスを受け取る変数へのポインター。このパラメーターは null にできます。 | ||||||||||||
| pcchPathBuf | DWORD* | inoutoptional | lpPathBuf パラメーターが指すバッファーのサイズ(文字数)を指定する変数へのポインター。入力時には、終端の null 文字用の領域を含むバッファーの全体サイズを指定します。渡されたバッファーが小さすぎる場合、返されるカウントには終端の null 文字は含まれません。 lpPathBuf が null の場合、pcchBuf も null にできます。 |
戻り値の型: DWORD
公式ドキュメント
MsiProvideComponent 関数は、必要なインストールを実行したうえで、コンポーネントの完全なパスを返します。この関数は、必要に応じてソースの入力を求め、機能の使用回数をインクリメントします。(Unicode)
戻り値
| 値 | 意味 |
|---|---|
| 構成データが破損しています。 | |
| 機能が存在しないか破損しています。このエラーは dwInstallMode = INSTALLMODE_EXISTING の場合に返されます。 | |
| インストールに失敗しました。 | |
| 要求されているコンポーネントは、このコンピューター上で無効になっています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 関数は正常に完了しました。 | |
| 機能 ID が既知の機能を識別していません。 | |
| 製品コードが既知の製品を識別していません。 | |
| 認識されない製品名または機能名が関数に渡されました。 | |
| バッファーオーバーフローが返されました。 | |
| ソースを検出できません。 |
詳細については、 Displayed Error Messages を参照してください。
解説(Remarks)
MsiProvideComponent 関数が成功すると、pcchPathBuf パラメーターには lpPathBuf 内の文字列の長さが格納されます。
MsiProvideComponent 関数は、 MsiUseFeature、 MsiConfigureFeature、 MsiGetComponentPath の機能を組み合わせたものです。MsiProvideComponent 関数を使用すると、呼び出しシーケンスを簡素化できます。ただし、この関数は使用回数をインクリメントするため、不正確な使用回数を防ぐために慎重に使用してください。また、MsiProvideComponent 関数は、個々の呼び出しを連続して行う場合に比べて柔軟性が低くなります。
アプリケーションが予期しない状況から回復している場合、アプリケーションはすでに MsiUseFeature を呼び出して使用回数をインクリメントしている可能性があります。この場合、使用回数を再びインクリメントしないために、アプリケーションは MsiProvideComponent の代わりに MsiConfigureFeature を呼び出す必要があります。
INSTALLMODE_EXISTING オプションは、REINSTALLMODE フラグと組み合わせて使用することはできません。
破損したファイルや誤ったバージョンのファイルを含むコンポーネントを持つ機能は、ユーザーが明示的に再インストールするか、アプリケーションが MsiReinstallFeature を呼び出すことによって再インストールする必要があります。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiProvideComponent を定義します。エンコーディング中立のエイリアスと、エンコーディング中立でないコードを混在させて使用すると、不一致が生じ、コンパイルエラーまたは実行時エラーが発生する可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiProvideComponentW(
LPCWSTR szProduct,
LPCWSTR szFeature,
LPCWSTR szComponent,
DWORD dwInstallMode,
LPWSTR lpPathBuf, // optional
DWORD* pcchPathBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiProvideComponentW(
[MarshalAs(UnmanagedType.LPWStr)] string szProduct, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szFeature, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szComponent, // LPCWSTR
uint dwInstallMode, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf, // LPWSTR optional, out
IntPtr pcchPathBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiProvideComponentW(
<MarshalAs(UnmanagedType.LPWStr)> szProduct As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szFeature As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szComponent As String, ' LPCWSTR
dwInstallMode As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> lpPathBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchPathBuf As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szProduct : LPCWSTR
' szFeature : LPCWSTR
' szComponent : LPCWSTR
' dwInstallMode : DWORD
' lpPathBuf : LPWSTR optional, out
' pcchPathBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiProvideComponentW Lib "msi" ( _
ByVal szProduct As LongPtr, _
ByVal szFeature As LongPtr, _
ByVal szComponent As LongPtr, _
ByVal dwInstallMode As Long, _
ByVal lpPathBuf As LongPtr, _
ByVal pcchPathBuf 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
MsiProvideComponentW = ctypes.windll.msi.MsiProvideComponentW
MsiProvideComponentW.restype = wintypes.DWORD
MsiProvideComponentW.argtypes = [
wintypes.LPCWSTR, # szProduct : LPCWSTR
wintypes.LPCWSTR, # szFeature : LPCWSTR
wintypes.LPCWSTR, # szComponent : LPCWSTR
wintypes.DWORD, # dwInstallMode : DWORD
wintypes.LPWSTR, # lpPathBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchPathBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiProvideComponentW = Fiddle::Function.new(
lib['MsiProvideComponentW'],
[
Fiddle::TYPE_VOIDP, # szProduct : LPCWSTR
Fiddle::TYPE_VOIDP, # szFeature : LPCWSTR
Fiddle::TYPE_VOIDP, # szComponent : LPCWSTR
-Fiddle::TYPE_INT, # dwInstallMode : DWORD
Fiddle::TYPE_VOIDP, # lpPathBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchPathBuf : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiProvideComponentW(
szProduct: *const u16, // LPCWSTR
szFeature: *const u16, // LPCWSTR
szComponent: *const u16, // LPCWSTR
dwInstallMode: u32, // DWORD
lpPathBuf: *mut u16, // LPWSTR optional, out
pcchPathBuf: *mut u32 // DWORD* optional, in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiProvideComponentW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] string szFeature, [MarshalAs(UnmanagedType.LPWStr)] string szComponent, uint dwInstallMode, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf, IntPtr pcchPathBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiProvideComponentW' -Namespace Win32 -PassThru
# $api::MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)#uselib "msi.dll"
#func global MsiProvideComponentW "MsiProvideComponentW" wptr, wptr, wptr, wptr, wptr, wptr
; MsiProvideComponentW szProduct, szFeature, szComponent, dwInstallMode, varptr(lpPathBuf), varptr(pcchPathBuf) ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; szFeature : LPCWSTR -> "wptr"
; szComponent : LPCWSTR -> "wptr"
; dwInstallMode : DWORD -> "wptr"
; lpPathBuf : LPWSTR optional, out -> "wptr"
; pcchPathBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiProvideComponentW "MsiProvideComponentW" wstr, wstr, wstr, int, var, var ; res = MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf) ; szProduct : LPCWSTR -> "wstr" ; szFeature : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; dwInstallMode : DWORD -> "int" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiProvideComponentW "MsiProvideComponentW" wstr, wstr, wstr, int, sptr, sptr ; res = MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, varptr(lpPathBuf), varptr(pcchPathBuf)) ; szProduct : LPCWSTR -> "wstr" ; szFeature : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; dwInstallMode : DWORD -> "int" ; lpPathBuf : LPWSTR optional, out -> "sptr" ; pcchPathBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiProvideComponentW(LPCWSTR szProduct, LPCWSTR szFeature, LPCWSTR szComponent, DWORD dwInstallMode, LPWSTR lpPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiProvideComponentW "MsiProvideComponentW" wstr, wstr, wstr, int, var, var ; res = MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf) ; szProduct : LPCWSTR -> "wstr" ; szFeature : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; dwInstallMode : DWORD -> "int" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiProvideComponentW(LPCWSTR szProduct, LPCWSTR szFeature, LPCWSTR szComponent, DWORD dwInstallMode, LPWSTR lpPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiProvideComponentW "MsiProvideComponentW" wstr, wstr, wstr, int, intptr, intptr ; res = MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, varptr(lpPathBuf), varptr(pcchPathBuf)) ; szProduct : LPCWSTR -> "wstr" ; szFeature : LPCWSTR -> "wstr" ; szComponent : LPCWSTR -> "wstr" ; dwInstallMode : DWORD -> "int" ; lpPathBuf : LPWSTR optional, out -> "intptr" ; pcchPathBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiProvideComponentW = msi.NewProc("MsiProvideComponentW")
)
// szProduct (LPCWSTR), szFeature (LPCWSTR), szComponent (LPCWSTR), dwInstallMode (DWORD), lpPathBuf (LPWSTR optional, out), pcchPathBuf (DWORD* optional, in/out)
r1, _, err := procMsiProvideComponentW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProduct))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFeature))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
uintptr(dwInstallMode),
uintptr(lpPathBuf),
uintptr(pcchPathBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiProvideComponentW(
szProduct: PWideChar; // LPCWSTR
szFeature: PWideChar; // LPCWSTR
szComponent: PWideChar; // LPCWSTR
dwInstallMode: DWORD; // DWORD
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiProvideComponentW';result := DllCall("msi\MsiProvideComponentW"
, "WStr", szProduct ; LPCWSTR
, "WStr", szFeature ; LPCWSTR
, "WStr", szComponent ; LPCWSTR
, "UInt", dwInstallMode ; DWORD
, "Ptr", lpPathBuf ; LPWSTR optional, out
, "Ptr", pcchPathBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf) = DLL("msi.dll", "dword MsiProvideComponentW(char*, char*, char*, dword, char*, void*)")
# 呼び出し: MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)
# szProduct : LPCWSTR -> "char*"
# szFeature : LPCWSTR -> "char*"
# szComponent : LPCWSTR -> "char*"
# dwInstallMode : DWORD -> "dword"
# lpPathBuf : LPWSTR optional, out -> "char*"
# pcchPathBuf : 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 MsiProvideComponentW(
szProduct: [*c]const u16, // LPCWSTR
szFeature: [*c]const u16, // LPCWSTR
szComponent: [*c]const u16, // LPCWSTR
dwInstallMode: u32, // DWORD
lpPathBuf: [*c]u16, // LPWSTR optional, out
pcchPathBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiProvideComponentW(
szProduct: WideCString, # LPCWSTR
szFeature: WideCString, # LPCWSTR
szComponent: WideCString, # LPCWSTR
dwInstallMode: uint32, # DWORD
lpPathBuf: ptr uint16, # LPWSTR optional, out
pcchPathBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiProvideComponentW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiProvideComponentW(
const(wchar)* szProduct, // LPCWSTR
const(wchar)* szFeature, // LPCWSTR
const(wchar)* szComponent, // LPCWSTR
uint dwInstallMode, // DWORD
wchar* lpPathBuf, // LPWSTR optional, out
uint* pcchPathBuf // DWORD* optional, in/out
);ccall((:MsiProvideComponentW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Cwstring, UInt32, Ptr{UInt16}, Ptr{UInt32}),
szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)
# szProduct : LPCWSTR -> Cwstring
# szFeature : LPCWSTR -> Cwstring
# szComponent : LPCWSTR -> Cwstring
# dwInstallMode : DWORD -> UInt32
# lpPathBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchPathBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiProvideComponentW(
const uint16_t* szProduct,
const uint16_t* szFeature,
const uint16_t* szComponent,
uint32_t dwInstallMode,
uint16_t* lpPathBuf,
uint32_t* pcchPathBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)
-- szProduct : LPCWSTR
-- szFeature : LPCWSTR
-- szComponent : LPCWSTR
-- dwInstallMode : DWORD
-- lpPathBuf : LPWSTR optional, out
-- pcchPathBuf : 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 MsiProvideComponentW = lib.func('__stdcall', 'MsiProvideComponentW', 'uint32_t', ['str16', 'str16', 'str16', 'uint32_t', 'uint16_t *', 'uint32_t *']);
// MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)
// szProduct : LPCWSTR -> 'str16'
// szFeature : LPCWSTR -> 'str16'
// szComponent : LPCWSTR -> 'str16'
// dwInstallMode : DWORD -> 'uint32_t'
// lpPathBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchPathBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiProvideComponentW: { parameters: ["buffer", "buffer", "buffer", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf)
// szProduct : LPCWSTR -> "buffer"
// szFeature : LPCWSTR -> "buffer"
// szComponent : LPCWSTR -> "buffer"
// dwInstallMode : DWORD -> "u32"
// lpPathBuf : LPWSTR optional, out -> "buffer"
// pcchPathBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiProvideComponentW(
const uint16_t* szProduct,
const uint16_t* szFeature,
const uint16_t* szComponent,
uint32_t dwInstallMode,
uint16_t* lpPathBuf,
uint32_t* pcchPathBuf);
C, "msi.dll");
// $ffi->MsiProvideComponentW(szProduct, szFeature, szComponent, dwInstallMode, lpPathBuf, pcchPathBuf);
// szProduct : LPCWSTR
// szFeature : LPCWSTR
// szComponent : LPCWSTR
// dwInstallMode : DWORD
// lpPathBuf : LPWSTR optional, out
// pcchPathBuf : 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 MsiProvideComponentW(
WString szProduct, // LPCWSTR
WString szFeature, // LPCWSTR
WString szComponent, // LPCWSTR
int dwInstallMode, // DWORD
char[] lpPathBuf, // LPWSTR optional, out
IntByReference pcchPathBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiProvideComponentW = MsiProvideComponentW(
szProduct : UInt16*, # LPCWSTR
szFeature : UInt16*, # LPCWSTR
szComponent : UInt16*, # LPCWSTR
dwInstallMode : UInt32, # DWORD
lpPathBuf : UInt16*, # LPWSTR optional, out
pcchPathBuf : UInt32* # DWORD* optional, in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MsiProvideComponentWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiProvideComponentWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Uint32>);
final MsiProvideComponentW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiProvideComponentWNative, MsiProvideComponentWDart>('MsiProvideComponentW');
// szProduct : LPCWSTR -> Pointer<Utf16>
// szFeature : LPCWSTR -> Pointer<Utf16>
// szComponent : LPCWSTR -> Pointer<Utf16>
// dwInstallMode : DWORD -> Uint32
// lpPathBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchPathBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiProvideComponentW(
szProduct: PWideChar; // LPCWSTR
szFeature: PWideChar; // LPCWSTR
szComponent: PWideChar; // LPCWSTR
dwInstallMode: DWORD; // DWORD
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiProvideComponentW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiProvideComponentW"
c_MsiProvideComponentW :: CWString -> CWString -> CWString -> Word32 -> CWString -> Ptr Word32 -> IO Word32
-- szProduct : LPCWSTR -> CWString
-- szFeature : LPCWSTR -> CWString
-- szComponent : LPCWSTR -> CWString
-- dwInstallMode : DWORD -> Word32
-- lpPathBuf : LPWSTR optional, out -> CWString
-- pcchPathBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msiprovidecomponentw =
foreign "MsiProvideComponentW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szProduct : LPCWSTR -> (ptr uint16_t) *)
(* szFeature : LPCWSTR -> (ptr uint16_t) *)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* dwInstallMode : DWORD -> uint32_t *)
(* lpPathBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchPathBuf : 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 ("MsiProvideComponentW" msi-provide-component-w :convention :stdcall) :uint32
(sz-product (:string :encoding :utf-16le)) ; LPCWSTR
(sz-feature (:string :encoding :utf-16le)) ; LPCWSTR
(sz-component (:string :encoding :utf-16le)) ; LPCWSTR
(dw-install-mode :uint32) ; DWORD
(lp-path-buf :pointer) ; LPWSTR optional, out
(pcch-path-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiProvideComponentW = Win32::API::More->new('msi',
'DWORD MsiProvideComponentW(LPCWSTR szProduct, LPCWSTR szFeature, LPCWSTR szComponent, DWORD dwInstallMode, LPWSTR lpPathBuf, LPVOID pcchPathBuf)');
# my $ret = $MsiProvideComponentW->Call($szProduct, $szFeature, $szComponent, $dwInstallMode, $lpPathBuf, $pcchPathBuf);
# szProduct : LPCWSTR -> LPCWSTR
# szFeature : LPCWSTR -> LPCWSTR
# szComponent : LPCWSTR -> LPCWSTR
# dwInstallMode : DWORD -> DWORD
# lpPathBuf : LPWSTR optional, out -> LPWSTR
# pcchPathBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiProvideComponentA (ANSI版) — コンポーネントを必要に応じインストールしパスを返す(ANSI版)。