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

MsiGetProductInfoW

関数
インストール済み製品の属性情報を取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetProductInfoW(
    LPCWSTR szProduct,
    LPCWSTR szAttribute,
    LPWSTR lpValueBuf,   // optional
    DWORD* pcchValueBuf   // optional
);

パラメーター

名前方向
szProductLPCWSTRin
szAttributeLPCWSTRin
lpValueBufLPWSTRoutoptional
pcchValueBufDWORD*inoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

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

MsiGetProductInfoW = ctypes.windll.msi.MsiGetProductInfoW
MsiGetProductInfoW.restype = wintypes.DWORD
MsiGetProductInfoW.argtypes = [
    wintypes.LPCWSTR,  # szProduct : LPCWSTR
    wintypes.LPCWSTR,  # szAttribute : LPCWSTR
    wintypes.LPWSTR,  # lpValueBuf : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchValueBuf : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetProductInfoW = msi.NewProc("MsiGetProductInfoW")
)

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