MsiGetProductInfoExW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductInfoExW(
LPCWSTR szProductCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
LPCWSTR szProperty,
LPWSTR szValue, // optional
DWORD* pcchValue // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szProductCode | LPCWSTR | in | 照会対象となる製品インスタンスの ProductCode GUID。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| szUserSid | LPCWSTR | inoptional | 照会対象の製品インスタンスが存在するアカウントのセキュリティ識別子 (SID)。NULL を指定すると現在のユーザーの SID を表します。
注 特別な SID 文字列 "S-1-5-18" (system) は、コンピューター単位 (per-machine) でインストールされた製品の列挙には使用できません。dwContext が "MSIINSTALLCONTEXT_MACHINE" の場合、szUserSid は NULL でなければなりません。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dwContext | MSIINSTALLCONTEXT | in | 照会対象の製品インスタンスのインストールコンテキスト。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| szProperty | LPCWSTR | in | 照会対象のプロパティ。 取得するプロパティ。次の表に示すプロパティは、既にインストールされているアプリケーションからのみ取得できます。すべての必須プロパティは取得可能であることが保証されますが、その他のプロパティはそのプロパティが設定されている場合にのみ取得できます。詳細については、 Required Properties および Properties を参照してください。
インストール済みのアプリケーションから製品 ID、登録された所有者、または登録された会社を取得するには、szProperty に次のいずれかのテキスト文字列値を設定します。
製品のインスタンスタイプを取得するには、szProperty に次の値を設定します。このプロパティは、アドバタイズされた製品またはインストール済みの製品で利用できます。
次の表に示すプロパティは、アドバタイズされた製品またはインストール済みの製品から取得できます。これらのプロパティは、現在のユーザーアカウント以外のユーザーアカウントについて、ユーザー単位かつ非管理対象 (per-user-unmanaged) コンテキストでインストールされた製品インスタンスでは取得できません。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| szValue | LPWSTR | outoptional | プロパティ値を受け取るバッファーへのポインター。このバッファーは情報を格納できる十分な大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、*pcchValue に終端の NULL 文字を含まない値の TCHAR 数を設定します。 lpValue に NULL を設定し、pcchValue に有効なポインターを設定した場合、関数は ERROR_SUCCESS を返し、pcchValue に終端の NULL 文字を含まない値の TCHAR 数を設定します。その後、pcchValue + 1 文字を格納できる十分な大きさの lpValue バッファーを用意して関数を再度呼び出すことで、値を取得できます。 lpValue と pcchValue の両方に NULL を設定した場合、値が存在すれば関数は値を取得せずに ERROR_SUCCESS を返します。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pcchValue | DWORD* | inoutoptional | lpValue バッファー内の TCHAR 数を指定する変数へのポインター。関数が戻るとき、このパラメーターには、関数が値を指定されたバッファーにコピーしたかどうかにかかわらず、要求された値のサイズが設定されます。サイズは、終端の null 文字を含まない、要求された値の TCHAR 数として返されます。 このパラメーターは、lpValue も NULL の場合に限り NULL に設定できます。それ以外の場合、関数は ERROR_INVALID_PARAMETER を返します。 |
戻り値の型: DWORD
公式ドキュメント
アドバタイズされた製品およびインストール済みの製品に関する製品情報を返します。(Unicode)
戻り値
MsiGetProductInfoEx 関数は次の値を返します。
| 戻り値 | 説明 |
|---|---|
| 現在のユーザー以外のユーザー向けにインストールされた製品の情報を取得するには、呼び出し元プロセスに管理者特権が必要です。 | |
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| バッファーが小さすぎて要求されたデータを格納できません。 | |
| 関数は正常に完了しました。 | |
| 製品はアドバタイズ解除されているか、アンインストールされています。 | |
|
プロパティが認識されません。
注 照会対象のアプリケーションがアドバタイズされているもののインストールされていない場合、MsiGetProductInfo 関数は ERROR_UNKNOWN_PROPERTY を返します。
|
|
| 予期しない内部エラーが発生しました。 |
解説(Remarks)
MsiGetProductInfoEx 関数が戻るとき、pcchValue パラメーターにはバッファーに格納された文字列の長さが含まれます。返されるカウントには終端の null 文字は含まれません。バッファーが十分な大きさでない場合、MsiGetProductInfoEx は ERROR_MORE_DATA を返し、pcchValue パラメーターには null 文字を含まない文字列のサイズが TCHAR 単位で含まれます。
MsiGetProductInfoEx 関数 (INSTALLPROPERTY_LOCALPACKAGE) は、キャッシュされたパッケージへのパスを返します。キャッシュされたパッケージは内部使用専用です。メンテナンスモードのインストールは、 MsiConfigureFeature、 MsiConfigureProduct、または MsiConfigureProductEx 関数を通じて呼び出す必要があります。
照会対象のアプリケーションがアドバタイズされているもののインストールされていない場合、MsiGetProductInfo 関数は ERROR_UNKNOWN_PROPERTY を返します。たとえば、アプリケーションがアドバタイズされているもののインストールされていない場合、INSTALLPROPERTY_INSTALLLOCATION への照会は ERROR_UNKNOWN_PROPERTY エラーを返します。
msi.h ヘッダーは MsiGetProductInfoEx を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetProductInfoExW(
LPCWSTR szProductCode,
LPCWSTR szUserSid, // optional
MSIINSTALLCONTEXT dwContext,
LPCWSTR szProperty,
LPWSTR szValue, // optional
DWORD* pcchValue // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetProductInfoExW(
[MarshalAs(UnmanagedType.LPWStr)] string szProductCode, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
[MarshalAs(UnmanagedType.LPWStr)] string szProperty, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szValue, // LPWSTR optional, out
IntPtr pcchValue // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetProductInfoExW(
<MarshalAs(UnmanagedType.LPWStr)> szProductCode As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As Integer, ' MSIINSTALLCONTEXT
<MarshalAs(UnmanagedType.LPWStr)> szProperty As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szValue As System.Text.StringBuilder, ' LPWSTR optional, out
pcchValue As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szProductCode : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : MSIINSTALLCONTEXT
' szProperty : LPCWSTR
' szValue : LPWSTR optional, out
' pcchValue : DWORD* optional, in/out
Declare PtrSafe Function MsiGetProductInfoExW Lib "msi" ( _
ByVal szProductCode As LongPtr, _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal szProperty As LongPtr, _
ByVal szValue As LongPtr, _
ByVal pcchValue 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
MsiGetProductInfoExW = ctypes.windll.msi.MsiGetProductInfoExW
MsiGetProductInfoExW.restype = wintypes.DWORD
MsiGetProductInfoExW.argtypes = [
wintypes.LPCWSTR, # szProductCode : LPCWSTR
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
ctypes.c_int, # dwContext : MSIINSTALLCONTEXT
wintypes.LPCWSTR, # szProperty : LPCWSTR
wintypes.LPWSTR, # szValue : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchValue : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetProductInfoExW = Fiddle::Function.new(
lib['MsiGetProductInfoExW'],
[
Fiddle::TYPE_VOIDP, # szProductCode : LPCWSTR
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
Fiddle::TYPE_INT, # dwContext : MSIINSTALLCONTEXT
Fiddle::TYPE_VOIDP, # szProperty : LPCWSTR
Fiddle::TYPE_VOIDP, # szValue : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchValue : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetProductInfoExW(
szProductCode: *const u16, // LPCWSTR
szUserSid: *const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
szProperty: *const u16, // LPCWSTR
szValue: *mut u16, // LPWSTR optional, out
pcchValue: *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 MsiGetProductInfoExW([MarshalAs(UnmanagedType.LPWStr)] string szProductCode, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, int dwContext, [MarshalAs(UnmanagedType.LPWStr)] string szProperty, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szValue, IntPtr pcchValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetProductInfoExW' -Namespace Win32 -PassThru
# $api::MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)#uselib "msi.dll"
#func global MsiGetProductInfoExW "MsiGetProductInfoExW" wptr, wptr, wptr, wptr, wptr, wptr
; MsiGetProductInfoExW szProductCode, szUserSid, dwContext, szProperty, varptr(szValue), varptr(pcchValue) ; 戻り値は stat
; szProductCode : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : MSIINSTALLCONTEXT -> "wptr"
; szProperty : LPCWSTR -> "wptr"
; szValue : LPWSTR optional, out -> "wptr"
; pcchValue : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetProductInfoExW "MsiGetProductInfoExW" wstr, wstr, int, wstr, var, var ; res = MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue) ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; szValue : LPWSTR optional, out -> "var" ; pcchValue : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetProductInfoExW "MsiGetProductInfoExW" wstr, wstr, int, wstr, sptr, sptr ; res = MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, varptr(szValue), varptr(pcchValue)) ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; szValue : LPWSTR optional, out -> "sptr" ; pcchValue : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty, LPWSTR szValue, DWORD* pcchValue) #uselib "msi.dll" #cfunc global MsiGetProductInfoExW "MsiGetProductInfoExW" wstr, wstr, int, wstr, var, var ; res = MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue) ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; szValue : LPWSTR optional, out -> "var" ; pcchValue : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty, LPWSTR szValue, DWORD* pcchValue) #uselib "msi.dll" #cfunc global MsiGetProductInfoExW "MsiGetProductInfoExW" wstr, wstr, int, wstr, intptr, intptr ; res = MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, varptr(szValue), varptr(pcchValue)) ; szProductCode : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : MSIINSTALLCONTEXT -> "int" ; szProperty : LPCWSTR -> "wstr" ; szValue : LPWSTR optional, out -> "intptr" ; pcchValue : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetProductInfoExW = msi.NewProc("MsiGetProductInfoExW")
)
// szProductCode (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (MSIINSTALLCONTEXT), szProperty (LPCWSTR), szValue (LPWSTR optional, out), pcchValue (DWORD* optional, in/out)
r1, _, err := procMsiGetProductInfoExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProductCode))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szProperty))),
uintptr(szValue),
uintptr(pcchValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetProductInfoExW(
szProductCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
szProperty: PWideChar; // LPCWSTR
szValue: PWideChar; // LPWSTR optional, out
pcchValue: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductInfoExW';result := DllCall("msi\MsiGetProductInfoExW"
, "WStr", szProductCode ; LPCWSTR
, "WStr", szUserSid ; LPCWSTR optional
, "Int", dwContext ; MSIINSTALLCONTEXT
, "WStr", szProperty ; LPCWSTR
, "Ptr", szValue ; LPWSTR optional, out
, "Ptr", pcchValue ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue) = DLL("msi.dll", "dword MsiGetProductInfoExW(char*, char*, int, char*, char*, void*)")
# 呼び出し: MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)
# szProductCode : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : MSIINSTALLCONTEXT -> "int"
# szProperty : LPCWSTR -> "char*"
# szValue : LPWSTR optional, out -> "char*"
# pcchValue : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetProductInfoExW(
szProductCode: [*c]const u16, // LPCWSTR
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: i32, // MSIINSTALLCONTEXT
szProperty: [*c]const u16, // LPCWSTR
szValue: [*c]u16, // LPWSTR optional, out
pcchValue: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetProductInfoExW(
szProductCode: WideCString, # LPCWSTR
szUserSid: WideCString, # LPCWSTR optional
dwContext: int32, # MSIINSTALLCONTEXT
szProperty: WideCString, # LPCWSTR
szValue: ptr uint16, # LPWSTR optional, out
pcchValue: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiGetProductInfoExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetProductInfoExW(
const(wchar)* szProductCode, // LPCWSTR
const(wchar)* szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
const(wchar)* szProperty, // LPCWSTR
wchar* szValue, // LPWSTR optional, out
uint* pcchValue // DWORD* optional, in/out
);ccall((:MsiGetProductInfoExW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, Int32, Cwstring, Ptr{UInt16}, Ptr{UInt32}),
szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)
# szProductCode : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : MSIINSTALLCONTEXT -> Int32
# szProperty : LPCWSTR -> Cwstring
# szValue : LPWSTR optional, out -> Ptr{UInt16}
# pcchValue : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetProductInfoExW(
const uint16_t* szProductCode,
const uint16_t* szUserSid,
int32_t dwContext,
const uint16_t* szProperty,
uint16_t* szValue,
uint32_t* pcchValue);
]]
local msi = ffi.load("msi")
-- msi.MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)
-- szProductCode : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : MSIINSTALLCONTEXT
-- szProperty : LPCWSTR
-- szValue : LPWSTR optional, out
-- pcchValue : DWORD* optional, in/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 MsiGetProductInfoExW = lib.func('__stdcall', 'MsiGetProductInfoExW', 'uint32_t', ['str16', 'str16', 'int32_t', 'str16', 'uint16_t *', 'uint32_t *']);
// MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)
// szProductCode : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : MSIINSTALLCONTEXT -> 'int32_t'
// szProperty : LPCWSTR -> 'str16'
// szValue : LPWSTR optional, out -> 'uint16_t *'
// pcchValue : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetProductInfoExW: { parameters: ["buffer", "buffer", "i32", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue)
// szProductCode : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : MSIINSTALLCONTEXT -> "i32"
// szProperty : LPCWSTR -> "buffer"
// szValue : LPWSTR optional, out -> "buffer"
// pcchValue : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetProductInfoExW(
const uint16_t* szProductCode,
const uint16_t* szUserSid,
int32_t dwContext,
const uint16_t* szProperty,
uint16_t* szValue,
uint32_t* pcchValue);
C, "msi.dll");
// $ffi->MsiGetProductInfoExW(szProductCode, szUserSid, dwContext, szProperty, szValue, pcchValue);
// szProductCode : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : MSIINSTALLCONTEXT
// szProperty : LPCWSTR
// szValue : LPWSTR optional, out
// pcchValue : 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.UNICODE_OPTIONS);
int MsiGetProductInfoExW(
WString szProductCode, // LPCWSTR
WString szUserSid, // LPCWSTR optional
int dwContext, // MSIINSTALLCONTEXT
WString szProperty, // LPCWSTR
char[] szValue, // LPWSTR optional, out
IntByReference pcchValue // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetProductInfoExW = MsiGetProductInfoExW(
szProductCode : UInt16*, # LPCWSTR
szUserSid : UInt16*, # LPCWSTR optional
dwContext : Int32, # MSIINSTALLCONTEXT
szProperty : UInt16*, # LPCWSTR
szValue : UInt16*, # LPWSTR optional, out
pcchValue : 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 MsiGetProductInfoExWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiGetProductInfoExWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>);
final MsiGetProductInfoExW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetProductInfoExWNative, MsiGetProductInfoExWDart>('MsiGetProductInfoExW');
// szProductCode : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : MSIINSTALLCONTEXT -> Int32
// szProperty : LPCWSTR -> Pointer<Utf16>
// szValue : LPWSTR optional, out -> Pointer<Utf16>
// pcchValue : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetProductInfoExW(
szProductCode: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: Integer; // MSIINSTALLCONTEXT
szProperty: PWideChar; // LPCWSTR
szValue: PWideChar; // LPWSTR optional, out
pcchValue: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetProductInfoExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetProductInfoExW"
c_MsiGetProductInfoExW :: CWString -> CWString -> Int32 -> CWString -> CWString -> Ptr Word32 -> IO Word32
-- szProductCode : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : MSIINSTALLCONTEXT -> Int32
-- szProperty : LPCWSTR -> CWString
-- szValue : LPWSTR optional, out -> CWString
-- pcchValue : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetproductinfoexw =
foreign "MsiGetProductInfoExW"
((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szProductCode : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : MSIINSTALLCONTEXT -> int32_t *)
(* szProperty : LPCWSTR -> (ptr uint16_t) *)
(* szValue : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchValue : 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 ("MsiGetProductInfoExW" msi-get-product-info-ex-w :convention :stdcall) :uint32
(sz-product-code (:string :encoding :utf-16le)) ; LPCWSTR
(sz-user-sid (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-context :int32) ; MSIINSTALLCONTEXT
(sz-property (:string :encoding :utf-16le)) ; LPCWSTR
(sz-value :pointer) ; LPWSTR optional, out
(pcch-value :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetProductInfoExW = Win32::API::More->new('msi',
'DWORD MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid, int dwContext, LPCWSTR szProperty, LPWSTR szValue, LPVOID pcchValue)');
# my $ret = $MsiGetProductInfoExW->Call($szProductCode, $szUserSid, $dwContext, $szProperty, $szValue, $pcchValue);
# szProductCode : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : MSIINSTALLCONTEXT -> int
# szProperty : LPCWSTR -> LPCWSTR
# szValue : LPWSTR optional, out -> LPWSTR
# pcchValue : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiGetProductInfoExA (ANSI版) — インストールコンテキストを指定して製品情報を取得する(ANSI版)。
- f MsiGetProductInfoW — インストール済み製品の属性情報を取得する(Unicode版)。
- f MsiConfigureFeatureW — 機能のインストール状態を構成変更する(Unicode版)。
- f MsiConfigureProductW — 製品のインストール状態を構成変更する(Unicode版)。
- f MsiConfigureProductExW — コマンドライン指定で製品の構成を変更する(Unicode版)。