MsiEnumComponentsExW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumComponentsExW(
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwIndex,
LPWSTR szInstalledComponentCode, // optional
MSIINSTALLCONTEXT* pdwInstalledContext, // optional
LPWSTR szSid, // optional
DWORD* pcchSid // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| szUserSid | LPCWSTR | inoptional | セキュリティ識別子 (SID) を含む null 終端文字列です。インストール済みコンポーネントの列挙は、この SID で識別されるユーザーにまで及びます。特別な SID 文字列 s-1-1-0 (Everyone) は、システム内のすべてのユーザーのすべての製品にわたる、インストール済みのすべてのコンポーネントの列挙を指定します。s-1-1-0 以外の SID 値は特定ユーザーのユーザー SID を指定し、列挙を、その指定ユーザーによってインストールされたアプリケーションのインスタンスに限定します。
注意
特別な SID 文字列 s-1-5-18 (System) は、コンピューター単位 (per-machine) のインストールコンテキストにインストールされたアプリケーションの列挙には使用できません。SID 値を s-1-5-18 に設定すると、ERROR_INVALID_PARAMETER が返されます。dwContext に MSIINSTALLCONTEXT_MACHINE のみが設定されている場合、szUserSid は NULL でなければなりません。 | ||||||||
| dwContext | DWORD | in | インストール済みコンポーネントの列挙を、指定したインストールコンテキストにインストールされた製品のインスタンスに限定するためのフラグです。列挙には、szUserSid で指定されたユーザーによってインストールされた製品のインスタンスのみが含まれます。
| ||||||||
| dwIndex | DWORD | in | 取得するコンポーネントのインデックスを指定します。MsiEnumComponentsEx 関数を最初に呼び出す際、このパラメーターは 0 でなければなりません。以降の各呼び出しでは、インデックスを 1 ずつ増やす必要があります。インデックスを増やすのは、前回の関数呼び出しが ERROR_SUCCESS を返した場合に限ります。 コンポーネントには順序がなく、関数からは任意の順序で返される可能性があります。 | ||||||||
| szInstalledComponentCode | LPWSTR | outoptional | インストール済みコンポーネントのコンポーネントコード GUID を受け取る出力バッファーです。バッファーの長さは、コンポーネントコードを含む null 終端文字列値を保持できるだけの大きさが必要です。先頭の 38 個の TCHAR 文字がコンポーネントの GUID を受け取り、39 文字目が終端の NULL 文字を受け取ります。 | ||||||||
| pdwInstalledContext | MSIINSTALLCONTEXT* | outoptional | コンポーネントをインストールしたアプリケーションのインストールコンテキストを示すフラグです。 | ||||||||
| szSid | LPWSTR | outoptional | コンポーネントを所有するアプリケーションをインストールしたユーザーを識別するセキュリティ識別子 (SID) を受け取ります。このアプリケーションのインスタンスがコンピューター単位 (per-machine) のインストールコンテキストにインストールされている場合、この場所には空文字列が格納されます。 この場所のバッファーの長さは、SID を含む null 終端文字列値を保持できるだけの大きさが必要です。バッファーが小さすぎる場合、関数は ERROR_MORE_DATA を返し、pcchSid が指す場所には、終端の NULL 文字を含まない SID 内の TCHAR の数が格納されます。 szSid を NULL に設定し、pcchSid がメモリ上の有効な場所を指すポインターである場合、関数は ERROR_SUCCESS を返し、その場所には終端の null 文字を含まない SID 内の TCHAR の数が格納されます。その後、szSid バッファーを *pcchSid + 1 文字を格納できる大きさにリサイズして関数を再度呼び出すことで、値を取得できます。
| ||||||||
| pcchSid | DWORD* | inoutoptional | 終端の null 文字を含まない SID 内の TCHAR の数を受け取ります。関数が戻るとき、この変数には、SID と終端の null 文字をバッファーの場所 (szSid が指す場所) に正常にコピーできたかどうかにかかわらず、要求された SID のサイズが設定されます。サイズは、終端の null 文字を含まない、要求された値内の TCHAR の数として返されます。 このパラメーターを NULL に設定できるのは、szSid も NULL である場合に限ります。そうでない場合、関数は ERROR_INVALID_PARAMETER を返します。szSid と pcchSid の両方を NULL に設定した場合、SID が存在すれば、関数は SID 値を取得せずに ERROR_SUCCESS を返します。 |
戻り値の型: DWORD
公式ドキュメント
MsiEnumComponentsEx 関数は、インストール済みのコンポーネントを列挙します。この関数は、呼び出されるたびに 1 つのコンポーネントのコンポーネントコードを取得します。コンポーネントコードは、コンポーネント、バージョン、および言語ごとに一意な文字列形式の GUID です。(Unicode)
戻り値
MsiEnumProductsEx 関数は、次のいずれかの値を返します。
| 戻り値 | 説明 |
|---|---|
| 現在のユーザー以外のユーザーがインストールしたアプリケーションのコンポーネントを列挙するには、管理者特権が必要です。 | |
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 列挙するコンポーネントがこれ以上ありません。 | |
| 関数は成功しました。 | |
| 指定されたバッファーが小さすぎて、値全体を保持できませんでした。 | |
| 関数は失敗しました。 |
解説(Remarks)
msi.h ヘッダーは MsiEnumComponentsEx をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング中立なエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumComponentsExW(
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwIndex,
LPWSTR szInstalledComponentCode, // optional
MSIINSTALLCONTEXT* pdwInstalledContext, // optional
LPWSTR szSid, // optional
DWORD* pcchSid // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiEnumComponentsExW(
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwIndex, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szInstalledComponentCode, // LPWSTR optional, out
IntPtr pdwInstalledContext, // MSIINSTALLCONTEXT* optional, out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szSid, // LPWSTR optional, out
IntPtr pcchSid // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiEnumComponentsExW(
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As UInteger, ' DWORD
dwIndex As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szInstalledComponentCode As System.Text.StringBuilder, ' LPWSTR optional, out
pdwInstalledContext As IntPtr, ' MSIINSTALLCONTEXT* optional, out
<MarshalAs(UnmanagedType.LPWStr)> szSid As System.Text.StringBuilder, ' LPWSTR optional, out
pcchSid As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szUserSid : LPCWSTR optional
' dwContext : DWORD
' dwIndex : DWORD
' szInstalledComponentCode : LPWSTR optional, out
' pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
' szSid : LPWSTR optional, out
' pcchSid : DWORD* optional, in/out
Declare PtrSafe Function MsiEnumComponentsExW Lib "msi" ( _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal dwIndex As Long, _
ByVal szInstalledComponentCode As LongPtr, _
ByVal pdwInstalledContext As LongPtr, _
ByVal szSid As LongPtr, _
ByVal pcchSid 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
MsiEnumComponentsExW = ctypes.windll.msi.MsiEnumComponentsExW
MsiEnumComponentsExW.restype = wintypes.DWORD
MsiEnumComponentsExW.argtypes = [
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
wintypes.DWORD, # dwContext : DWORD
wintypes.DWORD, # dwIndex : DWORD
wintypes.LPWSTR, # szInstalledComponentCode : LPWSTR optional, out
ctypes.c_void_p, # pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
wintypes.LPWSTR, # szSid : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchSid : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiEnumComponentsExW = Fiddle::Function.new(
lib['MsiEnumComponentsExW'],
[
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
-Fiddle::TYPE_INT, # dwContext : DWORD
-Fiddle::TYPE_INT, # dwIndex : DWORD
Fiddle::TYPE_VOIDP, # szInstalledComponentCode : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
Fiddle::TYPE_VOIDP, # szSid : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchSid : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiEnumComponentsExW(
szUserSid: *const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwIndex: u32, // DWORD
szInstalledComponentCode: *mut u16, // LPWSTR optional, out
pdwInstalledContext: *mut i32, // MSIINSTALLCONTEXT* optional, out
szSid: *mut u16, // LPWSTR optional, out
pcchSid: *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 MsiEnumComponentsExW([MarshalAs(UnmanagedType.LPWStr)] string szUserSid, uint dwContext, uint dwIndex, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szInstalledComponentCode, IntPtr pdwInstalledContext, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szSid, IntPtr pcchSid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiEnumComponentsExW' -Namespace Win32 -PassThru
# $api::MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)#uselib "msi.dll"
#func global MsiEnumComponentsExW "MsiEnumComponentsExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiEnumComponentsExW szUserSid, dwContext, dwIndex, varptr(szInstalledComponentCode), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid) ; 戻り値は stat
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : DWORD -> "wptr"
; dwIndex : DWORD -> "wptr"
; szInstalledComponentCode : LPWSTR optional, out -> "wptr"
; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "wptr"
; szSid : LPWSTR optional, out -> "wptr"
; pcchSid : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiEnumComponentsExW "MsiEnumComponentsExW" wstr, int, int, var, var, var, var ; res = MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid) ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szInstalledComponentCode : LPWSTR optional, out -> "var" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "var" ; szSid : LPWSTR optional, out -> "var" ; pcchSid : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiEnumComponentsExW "MsiEnumComponentsExW" wstr, int, int, sptr, sptr, sptr, sptr ; res = MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, varptr(szInstalledComponentCode), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid)) ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szInstalledComponentCode : LPWSTR optional, out -> "sptr" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "sptr" ; szSid : LPWSTR optional, out -> "sptr" ; pcchSid : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiEnumComponentsExW(LPCWSTR szUserSid, DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledComponentCode, MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, DWORD* pcchSid) #uselib "msi.dll" #cfunc global MsiEnumComponentsExW "MsiEnumComponentsExW" wstr, int, int, var, var, var, var ; res = MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid) ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szInstalledComponentCode : LPWSTR optional, out -> "var" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "var" ; szSid : LPWSTR optional, out -> "var" ; pcchSid : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiEnumComponentsExW(LPCWSTR szUserSid, DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledComponentCode, MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, DWORD* pcchSid) #uselib "msi.dll" #cfunc global MsiEnumComponentsExW "MsiEnumComponentsExW" wstr, int, int, intptr, intptr, intptr, intptr ; res = MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, varptr(szInstalledComponentCode), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid)) ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwIndex : DWORD -> "int" ; szInstalledComponentCode : LPWSTR optional, out -> "intptr" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "intptr" ; szSid : LPWSTR optional, out -> "intptr" ; pcchSid : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiEnumComponentsExW = msi.NewProc("MsiEnumComponentsExW")
)
// szUserSid (LPCWSTR optional), dwContext (DWORD), dwIndex (DWORD), szInstalledComponentCode (LPWSTR optional, out), pdwInstalledContext (MSIINSTALLCONTEXT* optional, out), szSid (LPWSTR optional, out), pcchSid (DWORD* optional, in/out)
r1, _, err := procMsiEnumComponentsExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(dwIndex),
uintptr(szInstalledComponentCode),
uintptr(pdwInstalledContext),
uintptr(szSid),
uintptr(pcchSid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiEnumComponentsExW(
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwIndex: DWORD; // DWORD
szInstalledComponentCode: PWideChar; // LPWSTR optional, out
pdwInstalledContext: Pointer; // MSIINSTALLCONTEXT* optional, out
szSid: PWideChar; // LPWSTR optional, out
pcchSid: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiEnumComponentsExW';result := DllCall("msi\MsiEnumComponentsExW"
, "WStr", szUserSid ; LPCWSTR optional
, "UInt", dwContext ; DWORD
, "UInt", dwIndex ; DWORD
, "Ptr", szInstalledComponentCode ; LPWSTR optional, out
, "Ptr", pdwInstalledContext ; MSIINSTALLCONTEXT* optional, out
, "Ptr", szSid ; LPWSTR optional, out
, "Ptr", pcchSid ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid) = DLL("msi.dll", "dword MsiEnumComponentsExW(char*, dword, dword, char*, void*, char*, void*)")
# 呼び出し: MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : DWORD -> "dword"
# dwIndex : DWORD -> "dword"
# szInstalledComponentCode : LPWSTR optional, out -> "char*"
# pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "void*"
# szSid : LPWSTR optional, out -> "char*"
# pcchSid : 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 MsiEnumComponentsExW(
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwIndex: u32, // DWORD
szInstalledComponentCode: [*c]u16, // LPWSTR optional, out
pdwInstalledContext: [*c]i32, // MSIINSTALLCONTEXT* optional, out
szSid: [*c]u16, // LPWSTR optional, out
pcchSid: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiEnumComponentsExW(
szUserSid: WideCString, # LPCWSTR optional
dwContext: uint32, # DWORD
dwIndex: uint32, # DWORD
szInstalledComponentCode: ptr uint16, # LPWSTR optional, out
pdwInstalledContext: ptr int32, # MSIINSTALLCONTEXT* optional, out
szSid: ptr uint16, # LPWSTR optional, out
pcchSid: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiEnumComponentsExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiEnumComponentsExW(
const(wchar)* szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwIndex, // DWORD
wchar* szInstalledComponentCode, // LPWSTR optional, out
int* pdwInstalledContext, // MSIINSTALLCONTEXT* optional, out
wchar* szSid, // LPWSTR optional, out
uint* pcchSid // DWORD* optional, in/out
);ccall((:MsiEnumComponentsExW, "msi.dll"), stdcall, UInt32,
(Cwstring, UInt32, UInt32, Ptr{UInt16}, Ptr{Int32}, Ptr{UInt16}, Ptr{UInt32}),
szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : DWORD -> UInt32
# dwIndex : DWORD -> UInt32
# szInstalledComponentCode : LPWSTR optional, out -> Ptr{UInt16}
# pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> Ptr{Int32}
# szSid : LPWSTR optional, out -> Ptr{UInt16}
# pcchSid : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiEnumComponentsExW(
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwIndex,
uint16_t* szInstalledComponentCode,
int32_t* pdwInstalledContext,
uint16_t* szSid,
uint32_t* pcchSid);
]]
local msi = ffi.load("msi")
-- msi.MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)
-- szUserSid : LPCWSTR optional
-- dwContext : DWORD
-- dwIndex : DWORD
-- szInstalledComponentCode : LPWSTR optional, out
-- pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
-- szSid : LPWSTR optional, out
-- pcchSid : 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 MsiEnumComponentsExW = lib.func('__stdcall', 'MsiEnumComponentsExW', 'uint32_t', ['str16', 'uint32_t', 'uint32_t', 'uint16_t *', 'int32_t *', 'uint16_t *', 'uint32_t *']);
// MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : DWORD -> 'uint32_t'
// dwIndex : DWORD -> 'uint32_t'
// szInstalledComponentCode : LPWSTR optional, out -> 'uint16_t *'
// pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> 'int32_t *'
// szSid : LPWSTR optional, out -> 'uint16_t *'
// pcchSid : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiEnumComponentsExW: { parameters: ["buffer", "u32", "u32", "buffer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid)
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : DWORD -> "u32"
// dwIndex : DWORD -> "u32"
// szInstalledComponentCode : LPWSTR optional, out -> "buffer"
// pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "pointer"
// szSid : LPWSTR optional, out -> "buffer"
// pcchSid : 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 MsiEnumComponentsExW(
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwIndex,
uint16_t* szInstalledComponentCode,
int32_t* pdwInstalledContext,
uint16_t* szSid,
uint32_t* pcchSid);
C, "msi.dll");
// $ffi->MsiEnumComponentsExW(szUserSid, dwContext, dwIndex, szInstalledComponentCode, pdwInstalledContext, szSid, pcchSid);
// szUserSid : LPCWSTR optional
// dwContext : DWORD
// dwIndex : DWORD
// szInstalledComponentCode : LPWSTR optional, out
// pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
// szSid : LPWSTR optional, out
// pcchSid : 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 MsiEnumComponentsExW(
WString szUserSid, // LPCWSTR optional
int dwContext, // DWORD
int dwIndex, // DWORD
char[] szInstalledComponentCode, // LPWSTR optional, out
IntByReference pdwInstalledContext, // MSIINSTALLCONTEXT* optional, out
char[] szSid, // LPWSTR optional, out
IntByReference pcchSid // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiEnumComponentsExW = MsiEnumComponentsExW(
szUserSid : UInt16*, # LPCWSTR optional
dwContext : UInt32, # DWORD
dwIndex : UInt32, # DWORD
szInstalledComponentCode : UInt16*, # LPWSTR optional, out
pdwInstalledContext : Int32*, # MSIINSTALLCONTEXT* optional, out
szSid : UInt16*, # LPWSTR optional, out
pcchSid : 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 MsiEnumComponentsExWNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiEnumComponentsExWDart = int Function(Pointer<Utf16>, int, int, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
final MsiEnumComponentsExW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiEnumComponentsExWNative, MsiEnumComponentsExWDart>('MsiEnumComponentsExW');
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : DWORD -> Uint32
// dwIndex : DWORD -> Uint32
// szInstalledComponentCode : LPWSTR optional, out -> Pointer<Utf16>
// pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> Pointer<Int32>
// szSid : LPWSTR optional, out -> Pointer<Utf16>
// pcchSid : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiEnumComponentsExW(
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwIndex: DWORD; // DWORD
szInstalledComponentCode: PWideChar; // LPWSTR optional, out
pdwInstalledContext: Pointer; // MSIINSTALLCONTEXT* optional, out
szSid: PWideChar; // LPWSTR optional, out
pcchSid: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiEnumComponentsExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiEnumComponentsExW"
c_MsiEnumComponentsExW :: CWString -> Word32 -> Word32 -> CWString -> Ptr Int32 -> CWString -> Ptr Word32 -> IO Word32
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : DWORD -> Word32
-- dwIndex : DWORD -> Word32
-- szInstalledComponentCode : LPWSTR optional, out -> CWString
-- pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> Ptr Int32
-- szSid : LPWSTR optional, out -> CWString
-- pcchSid : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msienumcomponentsexw =
foreign "MsiEnumComponentsExW"
((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : DWORD -> uint32_t *)
(* dwIndex : DWORD -> uint32_t *)
(* szInstalledComponentCode : LPWSTR optional, out -> (ptr uint16_t) *)
(* pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> (ptr int32_t) *)
(* szSid : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchSid : 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 ("MsiEnumComponentsExW" msi-enum-components-ex-w :convention :stdcall) :uint32
(sz-user-sid (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-context :uint32) ; DWORD
(dw-index :uint32) ; DWORD
(sz-installed-component-code :pointer) ; LPWSTR optional, out
(pdw-installed-context :pointer) ; MSIINSTALLCONTEXT* optional, out
(sz-sid :pointer) ; LPWSTR optional, out
(pcch-sid :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiEnumComponentsExW = Win32::API::More->new('msi',
'DWORD MsiEnumComponentsExW(LPCWSTR szUserSid, DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledComponentCode, LPVOID pdwInstalledContext, LPWSTR szSid, LPVOID pcchSid)');
# my $ret = $MsiEnumComponentsExW->Call($szUserSid, $dwContext, $dwIndex, $szInstalledComponentCode, $pdwInstalledContext, $szSid, $pcchSid);
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : DWORD -> DWORD
# dwIndex : DWORD -> DWORD
# szInstalledComponentCode : LPWSTR optional, out -> LPWSTR
# pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> LPVOID
# szSid : LPWSTR optional, out -> LPWSTR
# pcchSid : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiEnumComponentsExA (ANSI版) — コンテキストやユーザーを指定して登録済みコンポーネントを列挙する。
- f MsiEnumComponentsW — システムに登録されたコンポーネントをインデックス順に列挙する。