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

MsiEnumRelatedProductsA

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

シグネチャ

// msi.dll  (ANSI / -A)
#include <windows.h>

DWORD MsiEnumRelatedProductsA(
    LPCSTR lpUpgradeCode,
    DWORD dwReserved,   // optional
    DWORD iProductIndex,
    LPSTR lpProductBuf
);

パラメーター

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

戻り値の型: DWORD

公式ドキュメント

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

戻り値

意味
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  (ANSI / -A)
#include <windows.h>

DWORD MsiEnumRelatedProductsA(
    LPCSTR lpUpgradeCode,
    DWORD dwReserved,   // optional
    DWORD iProductIndex,
    LPSTR lpProductBuf
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiEnumRelatedProductsA(
    [MarshalAs(UnmanagedType.LPStr)] string lpUpgradeCode,   // LPCSTR
    uint dwReserved,   // DWORD optional
    uint iProductIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpProductBuf   // LPSTR out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiEnumRelatedProductsA(
    <MarshalAs(UnmanagedType.LPStr)> lpUpgradeCode As String,   ' LPCSTR
    dwReserved As UInteger,   ' DWORD optional
    iProductIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpProductBuf As System.Text.StringBuilder   ' LPSTR out
) As UInteger
End Function
' lpUpgradeCode : LPCSTR
' dwReserved : DWORD optional
' iProductIndex : DWORD
' lpProductBuf : LPSTR out
Declare PtrSafe Function MsiEnumRelatedProductsA Lib "msi" ( _
    ByVal lpUpgradeCode As String, _
    ByVal dwReserved As Long, _
    ByVal iProductIndex As Long, _
    ByVal lpProductBuf As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiEnumRelatedProductsA = msi.NewProc("MsiEnumRelatedProductsA")
)

// lpUpgradeCode (LPCSTR), dwReserved (DWORD optional), iProductIndex (DWORD), lpProductBuf (LPSTR out)
r1, _, err := procMsiEnumRelatedProductsA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpUpgradeCode))),
	uintptr(dwReserved),
	uintptr(iProductIndex),
	uintptr(lpProductBuf),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiEnumRelatedProductsA(
  lpUpgradeCode: PAnsiChar;   // LPCSTR
  dwReserved: DWORD;   // DWORD optional
  iProductIndex: DWORD;   // DWORD
  lpProductBuf: PAnsiChar   // LPSTR out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiEnumRelatedProductsA';
result := DllCall("msi\MsiEnumRelatedProductsA"
    , "AStr", lpUpgradeCode   ; LPCSTR
    , "UInt", dwReserved   ; DWORD optional
    , "UInt", iProductIndex   ; DWORD
    , "Ptr", lpProductBuf   ; LPSTR out
    , "UInt")   ; return: DWORD
●MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf) = DLL("msi.dll", "dword MsiEnumRelatedProductsA(char*, dword, dword, char*)")
# 呼び出し: MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf)
# lpUpgradeCode : LPCSTR -> "char*"
# dwReserved : DWORD optional -> "dword"
# iProductIndex : DWORD -> "dword"
# lpProductBuf : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "msi" fn MsiEnumRelatedProductsA(
    lpUpgradeCode: [*c]const u8, // LPCSTR
    dwReserved: u32, // DWORD optional
    iProductIndex: u32, // DWORD
    lpProductBuf: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) u32;
proc MsiEnumRelatedProductsA(
    lpUpgradeCode: cstring,  # LPCSTR
    dwReserved: uint32,  # DWORD optional
    iProductIndex: uint32,  # DWORD
    lpProductBuf: ptr char  # LPSTR out
): uint32 {.importc: "MsiEnumRelatedProductsA", stdcall, dynlib: "msi.dll".}
pragma(lib, "msi");
extern(Windows)
uint MsiEnumRelatedProductsA(
    const(char)* lpUpgradeCode,   // LPCSTR
    uint dwReserved,   // DWORD optional
    uint iProductIndex,   // DWORD
    char* lpProductBuf   // LPSTR out
);
ccall((:MsiEnumRelatedProductsA, "msi.dll"), stdcall, UInt32,
      (Cstring, UInt32, UInt32, Ptr{UInt8}),
      lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf)
# lpUpgradeCode : LPCSTR -> Cstring
# dwReserved : DWORD optional -> UInt32
# iProductIndex : DWORD -> UInt32
# lpProductBuf : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiEnumRelatedProductsA(
    const char* lpUpgradeCode,
    uint32_t dwReserved,
    uint32_t iProductIndex,
    char* lpProductBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf)
-- lpUpgradeCode : LPCSTR
-- dwReserved : DWORD optional
-- iProductIndex : DWORD
-- lpProductBuf : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiEnumRelatedProductsA = lib.func('__stdcall', 'MsiEnumRelatedProductsA', 'uint32_t', ['str', 'uint32_t', 'uint32_t', 'char *']);
// MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf)
// lpUpgradeCode : LPCSTR -> 'str'
// dwReserved : DWORD optional -> 'uint32_t'
// iProductIndex : DWORD -> 'uint32_t'
// lpProductBuf : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("msi.dll", {
  MsiEnumRelatedProductsA: { parameters: ["buffer", "u32", "u32", "buffer"], result: "u32" },
});
// lib.symbols.MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf)
// lpUpgradeCode : LPCSTR -> "buffer"
// dwReserved : DWORD optional -> "u32"
// iProductIndex : DWORD -> "u32"
// lpProductBuf : LPSTR out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiEnumRelatedProductsA(
    const char* lpUpgradeCode,
    uint32_t dwReserved,
    uint32_t iProductIndex,
    char* lpProductBuf);
C, "msi.dll");
// $ffi->MsiEnumRelatedProductsA(lpUpgradeCode, dwReserved, iProductIndex, lpProductBuf);
// lpUpgradeCode : LPCSTR
// dwReserved : DWORD optional
// iProductIndex : DWORD
// lpProductBuf : LPSTR 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.ASCII_OPTIONS);
    int MsiEnumRelatedProductsA(
        String lpUpgradeCode,   // LPCSTR
        int dwReserved,   // DWORD optional
        int iProductIndex,   // DWORD
        byte[] lpProductBuf   // LPSTR out
    );
}
@[Link("msi")]
lib Libmsi
  fun MsiEnumRelatedProductsA = MsiEnumRelatedProductsA(
    lpUpgradeCode : UInt8*,   # LPCSTR
    dwReserved : UInt32,   # DWORD optional
    iProductIndex : UInt32,   # DWORD
    lpProductBuf : UInt8*   # LPSTR out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

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

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

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

(cffi:defcfun ("MsiEnumRelatedProductsA" msi-enum-related-products-a :convention :stdcall) :uint32
  (lp-upgrade-code :string)   ; LPCSTR
  (dw-reserved :uint32)   ; DWORD optional
  (i-product-index :uint32)   ; DWORD
  (lp-product-buf :pointer))   ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MsiEnumRelatedProductsA = Win32::API::More->new('msi',
    'DWORD MsiEnumRelatedProductsA(LPCSTR lpUpgradeCode, DWORD dwReserved, DWORD iProductIndex, LPSTR lpProductBuf)');
# my $ret = $MsiEnumRelatedProductsA->Call($lpUpgradeCode, $dwReserved, $iProductIndex, $lpProductBuf);
# lpUpgradeCode : LPCSTR -> LPCSTR
# dwReserved : DWORD optional -> DWORD
# iProductIndex : DWORD -> DWORD
# lpProductBuf : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い