MsiGetProductInfoA
関数シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetProductInfoA(
LPCSTR szProduct,
LPCSTR szAttribute,
LPSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szProduct | LPCSTR | in | 製品の製品コードを指定します。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| szAttribute | LPCSTR | in | 取得するプロパティを指定します。 必須プロパティ は常に利用可能であることが保証されていますが、その他のプロパティはそのプロパティが設定されている場合にのみ利用できます。詳細については、Properties を参照してください。次の一覧に示すプロパティは、インストール済みのアプリケーションからのみ取得できます。
インストール済みのアプリケーションから製品 ID、登録された所有者、または登録された会社を取得するには、szProperty に次のテキスト文字列値のいずれかを設定します。
製品のインスタンスの種類を取得するには、szProperty に次の値を設定します。このプロパティは、アドバタイズ済みまたはインストール済みの製品で利用できます。
次の一覧に示すアドバタイズプロパティは、アドバタイズ済みまたはインストール済みのアプリケーションから取得できます。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lpValueBuf | LPSTR | outoptional | プロパティ値を受け取るバッファーへのポインター。このパラメーターは null にできます。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pcchValueBuf | DWORD* | inoutoptional | lpValueBuf パラメーターが指すバッファーのサイズを文字数で指定する変数へのポインター。入力時には、終端の null 文字用の領域を含むバッファーの全体サイズを指定します。渡されたバッファーが小さすぎる場合、返されるカウントには終端の null 文字は含まれません。 lpValueBuf が null の場合、pcchValueBuf も null にできます。この場合、関数はプロパティが製品に正しく登録されているかどうかを確認します。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetProductInfo 関数は、公開済みおよびインストール済みの製品に関する製品情報を返します。(ANSI)
戻り値
| 値 | 意味 |
|---|---|
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| バッファーが小さすぎて、要求されたデータを格納できません。 | |
| 関数が正常に完了しました。 | |
| 製品がアドバタイズ解除されているか、アンインストールされています。 | |
|
プロパティが認識されません。
注 クエリ対象のアプリケーションがアドバタイズされていてインストールされていない場合、MsiGetProductInfo 関数は ERROR_UNKNOWN_PROPERTY を返します。
|
解説(Remarks)
MsiGetProductInfo 関数が戻るとき、pcchValueBuf パラメーターにはバッファーに格納された文字列の長さが含まれます。返されるカウントには終端の null 文字は含まれません。バッファーが十分な大きさでない場合、MsiGetProductInfo は ERROR_MORE_DATA を返し、pcchValueBuf には null 文字を数えない文字列のサイズが文字数で格納されます。
MsiGetProductInfo(INSTALLPROPERTY_LOCALPACKAGE) は、必ずしもキャッシュされたパッケージへのパスを返すとは限りません。キャッシュされたパッケージは内部使用専用です。メンテナンスモードのインストールは、MsiConfigureFeature、MsiConfigureProduct、または MsiConfigureProductEx 関数を通じて呼び出す必要があります。
MsiGetProductInfo を使用して、インストール済みの製品でのみ利用可能なプロパティをアドバタイズ済みの製品に対してクエリしようとすると、関数は ERROR_UNKNOWN_PROPERTY を返します。たとえば、アプリケーションがアドバタイズされていてインストールされていない場合、INSTALLPROPERTY_INSTALLLOCATION プロパティへのクエリは ERROR_UNKNOWN_PROPERTY エラーを返します。
msi.h ヘッダーは MsiGetProductInfo を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディングに依存しないエイリアスの使用を、エンコーディングに依存しないわけではないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetProductInfoA(
LPCSTR szProduct,
LPCSTR szAttribute,
LPSTR lpValueBuf, // optional
DWORD* pcchValueBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetProductInfoA(
[MarshalAs(UnmanagedType.LPStr)] string szProduct, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string szAttribute, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpValueBuf, // LPSTR optional, out
IntPtr pcchValueBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetProductInfoA(
<MarshalAs(UnmanagedType.LPStr)> szProduct As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> szAttribute As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpValueBuf As System.Text.StringBuilder, ' LPSTR optional, out
pcchValueBuf As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szProduct : LPCSTR
' szAttribute : LPCSTR
' lpValueBuf : LPSTR optional, out
' pcchValueBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetProductInfoA Lib "msi" ( _
ByVal szProduct As String, _
ByVal szAttribute As String, _
ByVal lpValueBuf As String, _
ByVal pcchValueBuf As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetProductInfoA = ctypes.windll.msi.MsiGetProductInfoA
MsiGetProductInfoA.restype = wintypes.DWORD
MsiGetProductInfoA.argtypes = [
wintypes.LPCSTR, # szProduct : LPCSTR
wintypes.LPCSTR, # szAttribute : LPCSTR
wintypes.LPSTR, # lpValueBuf : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchValueBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductInfoA = Fiddle::Function.new(
lib['MsiGetProductInfoA'],
[
Fiddle::TYPE_VOIDP, # szProduct : LPCSTR
Fiddle::TYPE_VOIDP, # szAttribute : LPCSTR
Fiddle::TYPE_VOIDP, # lpValueBuf : LPSTR optional, out
Fiddle::TYPE_VOIDP, # pcchValueBuf : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetProductInfoA(
szProduct: *const u8, // LPCSTR
szAttribute: *const u8, // LPCSTR
lpValueBuf: *mut u8, // LPSTR optional, out
pcchValueBuf: *mut u32 // DWORD* optional, in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiGetProductInfoA([MarshalAs(UnmanagedType.LPStr)] string szProduct, [MarshalAs(UnmanagedType.LPStr)] string szAttribute, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpValueBuf, IntPtr pcchValueBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductInfoA' -Namespace Win32 -PassThru
# $api::MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf)#uselib "msi.dll"
#func global MsiGetProductInfoA "MsiGetProductInfoA" sptr, sptr, sptr, sptr
; MsiGetProductInfoA szProduct, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf) ; 戻り値は stat
; szProduct : LPCSTR -> "sptr"
; szAttribute : LPCSTR -> "sptr"
; lpValueBuf : LPSTR optional, out -> "sptr"
; pcchValueBuf : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetProductInfoA "MsiGetProductInfoA" str, str, var, var ; res = MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf) ; szProduct : LPCSTR -> "str" ; szAttribute : LPCSTR -> "str" ; lpValueBuf : LPSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductInfoA "MsiGetProductInfoA" str, str, sptr, sptr ; res = MsiGetProductInfoA(szProduct, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf)) ; szProduct : LPCSTR -> "str" ; szAttribute : LPCSTR -> "str" ; lpValueBuf : LPSTR optional, out -> "sptr" ; pcchValueBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute, LPSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetProductInfoA "MsiGetProductInfoA" str, str, var, var ; res = MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf) ; szProduct : LPCSTR -> "str" ; szAttribute : LPCSTR -> "str" ; lpValueBuf : LPSTR optional, out -> "var" ; pcchValueBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute, LPSTR lpValueBuf, DWORD* pcchValueBuf) #uselib "msi.dll" #cfunc global MsiGetProductInfoA "MsiGetProductInfoA" str, str, intptr, intptr ; res = MsiGetProductInfoA(szProduct, szAttribute, varptr(lpValueBuf), varptr(pcchValueBuf)) ; szProduct : LPCSTR -> "str" ; szAttribute : LPCSTR -> "str" ; lpValueBuf : LPSTR optional, out -> "intptr" ; pcchValueBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductInfoA = msi.NewProc("MsiGetProductInfoA")
)
// szProduct (LPCSTR), szAttribute (LPCSTR), lpValueBuf (LPSTR optional, out), pcchValueBuf (DWORD* optional, in/out)
r1, _, err := procMsiGetProductInfoA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szProduct))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szAttribute))),
uintptr(lpValueBuf),
uintptr(pcchValueBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductInfoA(
szProduct: PAnsiChar; // LPCSTR
szAttribute: PAnsiChar; // LPCSTR
lpValueBuf: PAnsiChar; // LPSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductInfoA';result := DllCall("msi\MsiGetProductInfoA"
, "AStr", szProduct ; LPCSTR
, "AStr", szAttribute ; LPCSTR
, "Ptr", lpValueBuf ; LPSTR optional, out
, "Ptr", pcchValueBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf) = DLL("msi.dll", "dword MsiGetProductInfoA(char*, char*, char*, void*)")
# 呼び出し: MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf)
# szProduct : LPCSTR -> "char*"
# szAttribute : LPCSTR -> "char*"
# lpValueBuf : LPSTR optional, out -> "char*"
# pcchValueBuf : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetProductInfoA(
szProduct: [*c]const u8, // LPCSTR
szAttribute: [*c]const u8, // LPCSTR
lpValueBuf: [*c]u8, // LPSTR optional, out
pcchValueBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetProductInfoA(
szProduct: cstring, # LPCSTR
szAttribute: cstring, # LPCSTR
lpValueBuf: ptr char, # LPSTR optional, out
pcchValueBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetProductInfoA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetProductInfoA(
const(char)* szProduct, // LPCSTR
const(char)* szAttribute, // LPCSTR
char* lpValueBuf, // LPSTR optional, out
uint* pcchValueBuf // DWORD* optional, in/out
);ccall((:MsiGetProductInfoA, "msi.dll"), stdcall, UInt32,
(Cstring, Cstring, Ptr{UInt8}, Ptr{UInt32}),
szProduct, szAttribute, lpValueBuf, pcchValueBuf)
# szProduct : LPCSTR -> Cstring
# szAttribute : LPCSTR -> Cstring
# lpValueBuf : LPSTR optional, out -> Ptr{UInt8}
# pcchValueBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetProductInfoA(
const char* szProduct,
const char* szAttribute,
char* lpValueBuf,
uint32_t* pcchValueBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf)
-- szProduct : LPCSTR
-- szAttribute : LPCSTR
-- lpValueBuf : LPSTR optional, out
-- pcchValueBuf : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetProductInfoA = lib.func('__stdcall', 'MsiGetProductInfoA', 'uint32_t', ['str', 'str', 'char *', 'uint32_t *']);
// MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf)
// szProduct : LPCSTR -> 'str'
// szAttribute : LPCSTR -> 'str'
// lpValueBuf : LPSTR optional, out -> 'char *'
// pcchValueBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetProductInfoA: { parameters: ["buffer", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf)
// szProduct : LPCSTR -> "buffer"
// szAttribute : LPCSTR -> "buffer"
// lpValueBuf : LPSTR optional, out -> "buffer"
// pcchValueBuf : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetProductInfoA(
const char* szProduct,
const char* szAttribute,
char* lpValueBuf,
uint32_t* pcchValueBuf);
C, "msi.dll");
// $ffi->MsiGetProductInfoA(szProduct, szAttribute, lpValueBuf, pcchValueBuf);
// szProduct : LPCSTR
// szAttribute : LPCSTR
// lpValueBuf : LPSTR optional, out
// pcchValueBuf : 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.ASCII_OPTIONS);
int MsiGetProductInfoA(
String szProduct, // LPCSTR
String szAttribute, // LPCSTR
byte[] lpValueBuf, // LPSTR optional, out
IntByReference pcchValueBuf // DWORD* optional, in/out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetProductInfoA = MsiGetProductInfoA(
szProduct : UInt8*, # LPCSTR
szAttribute : UInt8*, # LPCSTR
lpValueBuf : UInt8*, # LPSTR optional, out
pcchValueBuf : 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 MsiGetProductInfoANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>);
typedef MsiGetProductInfoADart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>);
final MsiGetProductInfoA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetProductInfoANative, MsiGetProductInfoADart>('MsiGetProductInfoA');
// szProduct : LPCSTR -> Pointer<Utf8>
// szAttribute : LPCSTR -> Pointer<Utf8>
// lpValueBuf : LPSTR optional, out -> Pointer<Utf8>
// pcchValueBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetProductInfoA(
szProduct: PAnsiChar; // LPCSTR
szAttribute: PAnsiChar; // LPCSTR
lpValueBuf: PAnsiChar; // LPSTR optional, out
pcchValueBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductInfoA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetProductInfoA"
c_MsiGetProductInfoA :: CString -> CString -> CString -> Ptr Word32 -> IO Word32
-- szProduct : LPCSTR -> CString
-- szAttribute : LPCSTR -> CString
-- lpValueBuf : LPSTR optional, out -> CString
-- pcchValueBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetproductinfoa =
foreign "MsiGetProductInfoA"
(string @-> string @-> string @-> (ptr uint32_t) @-> returning uint32_t)
(* szProduct : LPCSTR -> string *)
(* szAttribute : LPCSTR -> string *)
(* lpValueBuf : LPSTR optional, out -> string *)
(* pcchValueBuf : 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 ("MsiGetProductInfoA" msi-get-product-info-a :convention :stdcall) :uint32
(sz-product :string) ; LPCSTR
(sz-attribute :string) ; LPCSTR
(lp-value-buf :pointer) ; LPSTR optional, out
(pcch-value-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetProductInfoA = Win32::API::More->new('msi',
'DWORD MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute, LPSTR lpValueBuf, LPVOID pcchValueBuf)');
# my $ret = $MsiGetProductInfoA->Call($szProduct, $szAttribute, $lpValueBuf, $pcchValueBuf);
# szProduct : LPCSTR -> LPCSTR
# szAttribute : LPCSTR -> LPCSTR
# lpValueBuf : LPSTR optional, out -> LPSTR
# pcchValueBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f MsiGetProductInfoW (Unicode版) — インストール済み製品の属性情報を取得する(Unicode版)。
- f MsiGetProductInfoExA — インストールコンテキストを指定して製品情報を取得する(ANSI版)。