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

MsiInstallMissingComponentW

関数
製品の不足コンポーネントを指定した状態でインストールする。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiInstallMissingComponentW(
    LPCWSTR szProduct,
    LPCWSTR szComponent,
    INSTALLSTATE eInstallState
);

パラメーター

名前方向説明
szProductLPCWSTRin対象製品の製品コード(GUID)文字列。Unicode。
szComponentLPCWSTRinインストールする欠落コンポーネントのコンポーネントコード(GUID)文字列。
eInstallStateINSTALLSTATEinコンポーネントに設定する目的のインストール状態(INSTALLSTATE)。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD MsiInstallMissingComponentW(
    LPCWSTR szProduct,
    LPCWSTR szComponent,
    INSTALLSTATE eInstallState
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiInstallMissingComponentW(
    [MarshalAs(UnmanagedType.LPWStr)] string szProduct,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string szComponent,   // LPCWSTR
    int eInstallState   // INSTALLSTATE
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiInstallMissingComponentW(
    <MarshalAs(UnmanagedType.LPWStr)> szProduct As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> szComponent As String,   ' LPCWSTR
    eInstallState As Integer   ' INSTALLSTATE
) As UInteger
End Function
' szProduct : LPCWSTR
' szComponent : LPCWSTR
' eInstallState : INSTALLSTATE
Declare PtrSafe Function MsiInstallMissingComponentW Lib "msi" ( _
    ByVal szProduct As LongPtr, _
    ByVal szComponent As LongPtr, _
    ByVal eInstallState As Long) 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

MsiInstallMissingComponentW = ctypes.windll.msi.MsiInstallMissingComponentW
MsiInstallMissingComponentW.restype = wintypes.DWORD
MsiInstallMissingComponentW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    wintypes.LPCWSTR,  # szComponent : LPCWSTR
    ctypes.c_int,  # eInstallState : INSTALLSTATE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiInstallMissingComponentW = Fiddle::Function.new(
  lib['MsiInstallMissingComponentW'],
  [
    Fiddle::TYPE_VOIDP,  # szProduct : LPCWSTR
    Fiddle::TYPE_VOIDP,  # szComponent : LPCWSTR
    Fiddle::TYPE_INT,  # eInstallState : INSTALLSTATE
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiInstallMissingComponentW(
        szProduct: *const u16,  // LPCWSTR
        szComponent: *const u16,  // LPCWSTR
        eInstallState: i32  // INSTALLSTATE
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiInstallMissingComponentW([MarshalAs(UnmanagedType.LPWStr)] string szProduct, [MarshalAs(UnmanagedType.LPWStr)] string szComponent, int eInstallState);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiInstallMissingComponentW' -Namespace Win32 -PassThru
# $api::MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
#uselib "msi.dll"
#func global MsiInstallMissingComponentW "MsiInstallMissingComponentW" wptr, wptr, wptr
; MsiInstallMissingComponentW szProduct, szComponent, eInstallState   ; 戻り値は stat
; szProduct : LPCWSTR -> "wptr"
; szComponent : LPCWSTR -> "wptr"
; eInstallState : INSTALLSTATE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "msi.dll"
#cfunc global MsiInstallMissingComponentW "MsiInstallMissingComponentW" wstr, wstr, int
; res = MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
; szProduct : LPCWSTR -> "wstr"
; szComponent : LPCWSTR -> "wstr"
; eInstallState : INSTALLSTATE -> "int"
; DWORD MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
#uselib "msi.dll"
#cfunc global MsiInstallMissingComponentW "MsiInstallMissingComponentW" wstr, wstr, int
; res = MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
; szProduct : LPCWSTR -> "wstr"
; szComponent : LPCWSTR -> "wstr"
; eInstallState : INSTALLSTATE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiInstallMissingComponentW = msi.NewProc("MsiInstallMissingComponentW")
)

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

extern "msi" fn MsiInstallMissingComponentW(
    szProduct: [*c]const u16, // LPCWSTR
    szComponent: [*c]const u16, // LPCWSTR
    eInstallState: i32 // INSTALLSTATE
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc MsiInstallMissingComponentW(
    szProduct: WideCString,  # LPCWSTR
    szComponent: WideCString,  # LPCWSTR
    eInstallState: int32  # INSTALLSTATE
): uint32 {.importc: "MsiInstallMissingComponentW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "msi");
extern(Windows)
uint MsiInstallMissingComponentW(
    const(wchar)* szProduct,   // LPCWSTR
    const(wchar)* szComponent,   // LPCWSTR
    int eInstallState   // INSTALLSTATE
);
ccall((:MsiInstallMissingComponentW, "msi.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Int32),
      szProduct, szComponent, eInstallState)
# szProduct : LPCWSTR -> Cwstring
# szComponent : LPCWSTR -> Cwstring
# eInstallState : INSTALLSTATE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiInstallMissingComponentW(
    const uint16_t* szProduct,
    const uint16_t* szComponent,
    int32_t eInstallState);
]]
local msi = ffi.load("msi")
-- msi.MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
-- szProduct : LPCWSTR
-- szComponent : LPCWSTR
-- eInstallState : INSTALLSTATE
-- 構造体/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 MsiInstallMissingComponentW = lib.func('__stdcall', 'MsiInstallMissingComponentW', 'uint32_t', ['str16', 'str16', 'int32_t']);
// MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
// szProduct : LPCWSTR -> 'str16'
// szComponent : LPCWSTR -> 'str16'
// eInstallState : INSTALLSTATE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiInstallMissingComponentW: { parameters: ["buffer", "buffer", "i32"], result: "u32" },
});
// lib.symbols.MsiInstallMissingComponentW(szProduct, szComponent, eInstallState)
// szProduct : LPCWSTR -> "buffer"
// szComponent : LPCWSTR -> "buffer"
// eInstallState : INSTALLSTATE -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiInstallMissingComponentW(
    const uint16_t* szProduct,
    const uint16_t* szComponent,
    int32_t eInstallState);
C, "msi.dll");
// $ffi->MsiInstallMissingComponentW(szProduct, szComponent, eInstallState);
// szProduct : LPCWSTR
// szComponent : LPCWSTR
// eInstallState : INSTALLSTATE
// 構造体/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 MsiInstallMissingComponentW(
        WString szProduct,   // LPCWSTR
        WString szComponent,   // LPCWSTR
        int eInstallState   // INSTALLSTATE
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("msi")]
lib Libmsi
  fun MsiInstallMissingComponentW = MsiInstallMissingComponentW(
    szProduct : UInt16*,   # LPCWSTR
    szComponent : UInt16*,   # LPCWSTR
    eInstallState : Int32   # INSTALLSTATE
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MsiInstallMissingComponentWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef MsiInstallMissingComponentWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final MsiInstallMissingComponentW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiInstallMissingComponentWNative, MsiInstallMissingComponentWDart>('MsiInstallMissingComponentW');
// szProduct : LPCWSTR -> Pointer<Utf16>
// szComponent : LPCWSTR -> Pointer<Utf16>
// eInstallState : INSTALLSTATE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiInstallMissingComponentW(
  szProduct: PWideChar;   // LPCWSTR
  szComponent: PWideChar;   // LPCWSTR
  eInstallState: Integer   // INSTALLSTATE
): DWORD; stdcall;
  external 'msi.dll' name 'MsiInstallMissingComponentW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiInstallMissingComponentW"
  c_MsiInstallMissingComponentW :: CWString -> CWString -> Int32 -> IO Word32
-- szProduct : LPCWSTR -> CWString
-- szComponent : LPCWSTR -> CWString
-- eInstallState : INSTALLSTATE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msiinstallmissingcomponentw =
  foreign "MsiInstallMissingComponentW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning uint32_t)
(* szProduct : LPCWSTR -> (ptr uint16_t) *)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* eInstallState : INSTALLSTATE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiInstallMissingComponentW" msi-install-missing-component-w :convention :stdcall) :uint32
  (sz-product (:string :encoding :utf-16le))   ; LPCWSTR
  (sz-component (:string :encoding :utf-16le))   ; LPCWSTR
  (e-install-state :int32))   ; INSTALLSTATE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiInstallMissingComponentW = Win32::API::More->new('msi',
    'DWORD MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, int eInstallState)');
# my $ret = $MsiInstallMissingComponentW->Call($szProduct, $szComponent, $eInstallState);
# szProduct : LPCWSTR -> LPCWSTR
# szComponent : LPCWSTR -> LPCWSTR
# eInstallState : INSTALLSTATE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型