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

MsiEnumRelatedProductsW

関数
アップグレードコードに関連する製品をインデックス順に列挙する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiEnumRelatedProductsW(
    LPCWSTR lpUpgradeCode,
    DWORD dwReserved,   // optional
    DWORD iProductIndex,
    LPWSTR lpProductBuf
);

パラメーター

名前方向説明
lpUpgradeCodeLPCWSTRinインストーラーが列挙する関連製品のアップグレード コードを指定する、null で終わる文字列です。
dwReservedDWORDoptionalこのパラメーターは予約されており、0 を指定する必要があります。
iProductIndexDWORDin登録済み製品に対する 0 から始まるインデックスです。
lpProductBufLPWSTRout製品コード GUID を受け取るバッファーです。このバッファーの長さは 39 文字である必要があります。最初の 38 文字は GUID 用で、最後の 1 文字は終端の null 文字用です。

戻り値の型: DWORD

公式ドキュメント

MsiEnumRelatedProducts 関数は、指定したアップグレード コードを持つ製品を列挙します。この関数は、Property テーブルに指定の UpgradeCode プロパティを持ち、現在インストールまたはアドバタイズされている製品を一覧します。(Unicode)

戻り値

意味
ERROR_BAD_CONFIGURATION
構成データが破損しています。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。
ERROR_NO_MORE_ITEMS
返す製品がありません。
ERROR_NOT_ENOUGH_MEMORY
操作を完了するための十分なメモリがシステムにありません。Windows Server 2003 以降で使用できます。
ERROR_SUCCESS
値が列挙されました。

解説(Remarks)

UpgradeCode プロパティを参照してください。

特定のアップグレード コードを持ち、現在インストールまたはアドバタイズされている製品を列挙するには、アプリケーションはまず iProductIndex パラメーターを 0 に設定して MsiEnumRelatedProducts 関数を呼び出します。次に、iProductIndex パラメーターをインクリメントしながら、関数が ERROR_NO_MORE_ITEMS を返すまで MsiEnumRelatedProducts を呼び出します。ERROR_NO_MORE_ITEMS は、指定したアップグレード コードを持つ製品がこれ以上ないことを意味します。

すべての関連製品を列挙するために MsiEnumRelatedProducts を複数回呼び出す場合は、各呼び出しを同じスレッドから行う必要があります。

メモ

msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiEnumRelatedProducts を定義します。エンコーディングに依存しないエイリアスの使用と、エンコーディングに依存しないわけではないコードを混在させると、不一致が生じ、コンパイル エラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD MsiEnumRelatedProductsW(
    LPCWSTR lpUpgradeCode,
    DWORD dwReserved,   // optional
    DWORD iProductIndex,
    LPWSTR lpProductBuf
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiEnumRelatedProductsW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpUpgradeCode,   // LPCWSTR
    uint dwReserved,   // DWORD optional
    uint iProductIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpProductBuf   // LPWSTR out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiEnumRelatedProductsW(
    <MarshalAs(UnmanagedType.LPWStr)> lpUpgradeCode As String,   ' LPCWSTR
    dwReserved As UInteger,   ' DWORD optional
    iProductIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpProductBuf As System.Text.StringBuilder   ' LPWSTR out
) As UInteger
End Function
' lpUpgradeCode : LPCWSTR
' dwReserved : DWORD optional
' iProductIndex : DWORD
' lpProductBuf : LPWSTR out
Declare PtrSafe Function MsiEnumRelatedProductsW Lib "msi" ( _
    ByVal lpUpgradeCode As LongPtr, _
    ByVal dwReserved As Long, _
    ByVal iProductIndex As Long, _
    ByVal lpProductBuf 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

MsiEnumRelatedProductsW = ctypes.windll.msi.MsiEnumRelatedProductsW
MsiEnumRelatedProductsW.restype = wintypes.DWORD
MsiEnumRelatedProductsW.argtypes = [
    wintypes.LPCWSTR,  # lpUpgradeCode : LPCWSTR
    wintypes.DWORD,  # dwReserved : DWORD optional
    wintypes.DWORD,  # iProductIndex : DWORD
    wintypes.LPWSTR,  # lpProductBuf : LPWSTR out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiEnumRelatedProductsW = msi.NewProc("MsiEnumRelatedProductsW")
)

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

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

typedef MsiEnumRelatedProductsWNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>);
typedef MsiEnumRelatedProductsWDart = int Function(Pointer<Utf16>, int, int, Pointer<Utf16>);
final MsiEnumRelatedProductsW = DynamicLibrary.open('msi.dll')
    .lookupFunction<MsiEnumRelatedProductsWNative, MsiEnumRelatedProductsWDart>('MsiEnumRelatedProductsW');
// lpUpgradeCode : LPCWSTR -> Pointer<Utf16>
// dwReserved : DWORD optional -> Uint32
// iProductIndex : DWORD -> Uint32
// lpProductBuf : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MsiEnumRelatedProductsW(
  lpUpgradeCode: PWideChar;   // LPCWSTR
  dwReserved: DWORD;   // DWORD optional
  iProductIndex: DWORD;   // DWORD
  lpProductBuf: PWideChar   // LPWSTR out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiEnumRelatedProductsW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MsiEnumRelatedProductsW"
  c_MsiEnumRelatedProductsW :: CWString -> Word32 -> Word32 -> CWString -> IO Word32
-- lpUpgradeCode : LPCWSTR -> CWString
-- dwReserved : DWORD optional -> Word32
-- iProductIndex : DWORD -> Word32
-- lpProductBuf : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let msienumrelatedproductsw =
  foreign "MsiEnumRelatedProductsW"
    ((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* lpUpgradeCode : LPCWSTR -> (ptr uint16_t) *)
(* dwReserved : DWORD optional -> uint32_t *)
(* iProductIndex : DWORD -> uint32_t *)
(* lpProductBuf : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)

(cffi:defcfun ("MsiEnumRelatedProductsW" msi-enum-related-products-w :convention :stdcall) :uint32
  (lp-upgrade-code (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-reserved :uint32)   ; DWORD optional
  (i-product-index :uint32)   ; DWORD
  (lp-product-buf :pointer))   ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiEnumRelatedProductsW = Win32::API::More->new('msi',
    'DWORD MsiEnumRelatedProductsW(LPCWSTR lpUpgradeCode, DWORD dwReserved, DWORD iProductIndex, LPWSTR lpProductBuf)');
# my $ret = $MsiEnumRelatedProductsW->Call($lpUpgradeCode, $dwReserved, $iProductIndex, $lpProductBuf);
# lpUpgradeCode : LPCWSTR -> LPCWSTR
# dwReserved : DWORD optional -> DWORD
# iProductIndex : DWORD -> DWORD
# lpProductBuf : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い