MsiEnumClientsExW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumClientsExW(
LPCWSTR szComponent,
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwProductIndex,
LPWSTR szProductBuf, // optional
MSIINSTALLCONTEXT* pdwInstalledContext, // optional
LPWSTR szSid, // optional
DWORD* pcchSid // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| szComponent | LPCWSTR | in | コンポーネントを識別するコンポーネントコード GUID。この関数は、このコンポーネントを使用するアプリケーションを列挙します。 | ||||||||
| szUserSid | LPCWSTR | inoptional | セキュリティ識別子 (SID) を含む、null 終端された文字列値。アプリケーションの列挙は、この SID で識別されるユーザーに対して行われます。特殊な SID 文字列 s-1-1-0 (Everyone) は、システム内のすべてのユーザーのすべてのアプリケーションを列挙します。s-1-1-0 以外の SID 値は特定のユーザーのユーザー SID を指定し、その指定ユーザーがインストールしたアプリケーションのインスタンスを列挙します。
注意 特殊な SID 文字列 s-1-5-18 (System) は、コンピューター単位のインストールコンテキストに存在するアプリケーションの列挙には使用できません。SID 値を s-1-5-18 に設定すると ERROR_INVALID_PARAMETER が返されます。dwContext に MSIINSTALLCONTEXT_MACHINE のみを設定する場合、szUserSid の値は NULL でなければなりません。
| ||||||||
| dwContext | DWORD | in | 指定したインストールコンテキストにインストールされたアプリケーションのインスタンスに列挙を拡張するフラグです。列挙には、szUserSid で識別されるユーザーがインストールしたアプリケーションのインスタンスのみが含まれます。 次の値の組み合わせを指定できます。
| ||||||||
| dwProductIndex | DWORD | in | 取得するアプリケーションのインデックスを指定します。このパラメーターの値は、関数の最初の呼び出しではゼロ (0) でなければなりません。以降の各呼び出しでは、インデックスを 1 ずつ増やします。インデックスを増やすのは、前回の関数呼び出しが ERROR_SUCCESS を返した場合のみとしてください。 | ||||||||
| szProductBuf | LPWSTR | outoptional | アプリケーションの製品コードを受け取る文字列値です。この場所のバッファーの長さは、製品コードを含む null 終端文字列値を保持できる十分な大きさである必要があります。最初の 38 文字の TCHAR がコンポーネントの GUID を受け取り、39 文字目が終端の NULL 文字を受け取ります。 | ||||||||
| pdwInstalledContext | MSIINSTALLCONTEXT* | outoptional | アプリケーションのインストールコンテキストを示すフラグです。 次の値の組み合わせを指定できます。
| ||||||||
| szSid | LPWSTR | outoptional | アプリケーションをインストールしたユーザーを識別するセキュリティ識別子 (SID) を受け取ります。このアプリケーションのインスタンスがコンピューター単位のインストールコンテキストに存在する場合、この場所は空の文字列値を受け取ります。 バッファーの長さは、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
公式ドキュメント
MsiEnumClientsEx 関数は、指定したコンポーネントを使用するインストール済みアプリケーションを列挙します。この関数は、呼び出されるたびにアプリケーションの製品コードを 1 つ取得します。(Unicode)
戻り値
MsiEnumClientsEx 関数は、次のいずれかの値を返します。
| 戻り値 | 説明 |
|---|---|
| 現在のユーザー以外のユーザーがインストールしたアプリケーションのコンポーネントを列挙するには、管理者権限が必要です。 | |
| 構成データが破損しています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 列挙するアプリケーションがこれ以上ありません。 | |
| 関数は成功しました。 | |
| 指定されたバッファーが、値全体を保持するには小さすぎました。 | |
| 関数は失敗しました。 |
解説(Remarks)
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiEnumClientsEx を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不整合が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiEnumClientsExW(
LPCWSTR szComponent,
LPCWSTR szUserSid, // optional
DWORD dwContext,
DWORD dwProductIndex,
LPWSTR szProductBuf, // optional
MSIINSTALLCONTEXT* pdwInstalledContext, // optional
LPWSTR szSid, // optional
DWORD* pcchSid // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiEnumClientsExW(
[MarshalAs(UnmanagedType.LPWStr)] string szComponent, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwProductIndex, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szProductBuf, // 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 MsiEnumClientsExW(
<MarshalAs(UnmanagedType.LPWStr)> szComponent As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szUserSid As String, ' LPCWSTR optional
dwContext As UInteger, ' DWORD
dwProductIndex As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szProductBuf 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' szComponent : LPCWSTR
' szUserSid : LPCWSTR optional
' dwContext : DWORD
' dwProductIndex : DWORD
' szProductBuf : LPWSTR optional, out
' pdwInstalledContext : MSIINSTALLCONTEXT* optional, out
' szSid : LPWSTR optional, out
' pcchSid : DWORD* optional, in/out
Declare PtrSafe Function MsiEnumClientsExW Lib "msi" ( _
ByVal szComponent As LongPtr, _
ByVal szUserSid As LongPtr, _
ByVal dwContext As Long, _
ByVal dwProductIndex As Long, _
ByVal szProductBuf 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
MsiEnumClientsExW = ctypes.windll.msi.MsiEnumClientsExW
MsiEnumClientsExW.restype = wintypes.DWORD
MsiEnumClientsExW.argtypes = [
wintypes.LPCWSTR, # szComponent : LPCWSTR
wintypes.LPCWSTR, # szUserSid : LPCWSTR optional
wintypes.DWORD, # dwContext : DWORD
wintypes.DWORD, # dwProductIndex : DWORD
wintypes.LPWSTR, # szProductBuf : 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')
MsiEnumClientsExW = Fiddle::Function.new(
lib['MsiEnumClientsExW'],
[
Fiddle::TYPE_VOIDP, # szComponent : LPCWSTR
Fiddle::TYPE_VOIDP, # szUserSid : LPCWSTR optional
-Fiddle::TYPE_INT, # dwContext : DWORD
-Fiddle::TYPE_INT, # dwProductIndex : DWORD
Fiddle::TYPE_VOIDP, # szProductBuf : 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 MsiEnumClientsExW(
szComponent: *const u16, // LPCWSTR
szUserSid: *const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwProductIndex: u32, // DWORD
szProductBuf: *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 MsiEnumClientsExW([MarshalAs(UnmanagedType.LPWStr)] string szComponent, [MarshalAs(UnmanagedType.LPWStr)] string szUserSid, uint dwContext, uint dwProductIndex, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szProductBuf, IntPtr pdwInstalledContext, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szSid, IntPtr pcchSid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiEnumClientsExW' -Namespace Win32 -PassThru
# $api::MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)#uselib "msi.dll"
#func global MsiEnumClientsExW "MsiEnumClientsExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; MsiEnumClientsExW szComponent, szUserSid, dwContext, dwProductIndex, varptr(szProductBuf), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid) ; 戻り値は stat
; szComponent : LPCWSTR -> "wptr"
; szUserSid : LPCWSTR optional -> "wptr"
; dwContext : DWORD -> "wptr"
; dwProductIndex : DWORD -> "wptr"
; szProductBuf : 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 MsiEnumClientsExW "MsiEnumClientsExW" wstr, wstr, int, int, var, var, var, var ; res = MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid) ; szComponent : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwProductIndex : DWORD -> "int" ; szProductBuf : 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 MsiEnumClientsExW "MsiEnumClientsExW" wstr, wstr, int, int, sptr, sptr, sptr, sptr ; res = MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, varptr(szProductBuf), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid)) ; szComponent : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwProductIndex : DWORD -> "int" ; szProductBuf : LPWSTR optional, out -> "sptr" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "sptr" ; szSid : LPWSTR optional, out -> "sptr" ; pcchSid : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiEnumClientsExW(LPCWSTR szComponent, LPCWSTR szUserSid, DWORD dwContext, DWORD dwProductIndex, LPWSTR szProductBuf, MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, DWORD* pcchSid) #uselib "msi.dll" #cfunc global MsiEnumClientsExW "MsiEnumClientsExW" wstr, wstr, int, int, var, var, var, var ; res = MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid) ; szComponent : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwProductIndex : DWORD -> "int" ; szProductBuf : LPWSTR optional, out -> "var" ; pdwInstalledContext : MSIINSTALLCONTEXT* optional, out -> "var" ; szSid : LPWSTR optional, out -> "var" ; pcchSid : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiEnumClientsExW(LPCWSTR szComponent, LPCWSTR szUserSid, DWORD dwContext, DWORD dwProductIndex, LPWSTR szProductBuf, MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, DWORD* pcchSid) #uselib "msi.dll" #cfunc global MsiEnumClientsExW "MsiEnumClientsExW" wstr, wstr, int, int, intptr, intptr, intptr, intptr ; res = MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, varptr(szProductBuf), varptr(pdwInstalledContext), varptr(szSid), varptr(pcchSid)) ; szComponent : LPCWSTR -> "wstr" ; szUserSid : LPCWSTR optional -> "wstr" ; dwContext : DWORD -> "int" ; dwProductIndex : DWORD -> "int" ; szProductBuf : 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")
procMsiEnumClientsExW = msi.NewProc("MsiEnumClientsExW")
)
// szComponent (LPCWSTR), szUserSid (LPCWSTR optional), dwContext (DWORD), dwProductIndex (DWORD), szProductBuf (LPWSTR optional, out), pdwInstalledContext (MSIINSTALLCONTEXT* optional, out), szSid (LPWSTR optional, out), pcchSid (DWORD* optional, in/out)
r1, _, err := procMsiEnumClientsExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szComponent))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szUserSid))),
uintptr(dwContext),
uintptr(dwProductIndex),
uintptr(szProductBuf),
uintptr(pdwInstalledContext),
uintptr(szSid),
uintptr(pcchSid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiEnumClientsExW(
szComponent: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwProductIndex: DWORD; // DWORD
szProductBuf: 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 'MsiEnumClientsExW';result := DllCall("msi\MsiEnumClientsExW"
, "WStr", szComponent ; LPCWSTR
, "WStr", szUserSid ; LPCWSTR optional
, "UInt", dwContext ; DWORD
, "UInt", dwProductIndex ; DWORD
, "Ptr", szProductBuf ; LPWSTR optional, out
, "Ptr", pdwInstalledContext ; MSIINSTALLCONTEXT* optional, out
, "Ptr", szSid ; LPWSTR optional, out
, "Ptr", pcchSid ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid) = DLL("msi.dll", "dword MsiEnumClientsExW(char*, char*, dword, dword, char*, void*, char*, void*)")
# 呼び出し: MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)
# szComponent : LPCWSTR -> "char*"
# szUserSid : LPCWSTR optional -> "char*"
# dwContext : DWORD -> "dword"
# dwProductIndex : DWORD -> "dword"
# szProductBuf : 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 MsiEnumClientsExW(
szComponent: [*c]const u16, // LPCWSTR
szUserSid: [*c]const u16, // LPCWSTR optional
dwContext: u32, // DWORD
dwProductIndex: u32, // DWORD
szProductBuf: [*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 MsiEnumClientsExW(
szComponent: WideCString, # LPCWSTR
szUserSid: WideCString, # LPCWSTR optional
dwContext: uint32, # DWORD
dwProductIndex: uint32, # DWORD
szProductBuf: 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: "MsiEnumClientsExW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiEnumClientsExW(
const(wchar)* szComponent, // LPCWSTR
const(wchar)* szUserSid, // LPCWSTR optional
uint dwContext, // DWORD
uint dwProductIndex, // DWORD
wchar* szProductBuf, // LPWSTR optional, out
int* pdwInstalledContext, // MSIINSTALLCONTEXT* optional, out
wchar* szSid, // LPWSTR optional, out
uint* pcchSid // DWORD* optional, in/out
);ccall((:MsiEnumClientsExW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, UInt32, UInt32, Ptr{UInt16}, Ptr{Int32}, Ptr{UInt16}, Ptr{UInt32}),
szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)
# szComponent : LPCWSTR -> Cwstring
# szUserSid : LPCWSTR optional -> Cwstring
# dwContext : DWORD -> UInt32
# dwProductIndex : DWORD -> UInt32
# szProductBuf : 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 MsiEnumClientsExW(
const uint16_t* szComponent,
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwProductIndex,
uint16_t* szProductBuf,
int32_t* pdwInstalledContext,
uint16_t* szSid,
uint32_t* pcchSid);
]]
local msi = ffi.load("msi")
-- msi.MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)
-- szComponent : LPCWSTR
-- szUserSid : LPCWSTR optional
-- dwContext : DWORD
-- dwProductIndex : DWORD
-- szProductBuf : 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 MsiEnumClientsExW = lib.func('__stdcall', 'MsiEnumClientsExW', 'uint32_t', ['str16', 'str16', 'uint32_t', 'uint32_t', 'uint16_t *', 'int32_t *', 'uint16_t *', 'uint32_t *']);
// MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)
// szComponent : LPCWSTR -> 'str16'
// szUserSid : LPCWSTR optional -> 'str16'
// dwContext : DWORD -> 'uint32_t'
// dwProductIndex : DWORD -> 'uint32_t'
// szProductBuf : 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", {
MsiEnumClientsExW: { parameters: ["buffer", "buffer", "u32", "u32", "buffer", "pointer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid)
// szComponent : LPCWSTR -> "buffer"
// szUserSid : LPCWSTR optional -> "buffer"
// dwContext : DWORD -> "u32"
// dwProductIndex : DWORD -> "u32"
// szProductBuf : 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 MsiEnumClientsExW(
const uint16_t* szComponent,
const uint16_t* szUserSid,
uint32_t dwContext,
uint32_t dwProductIndex,
uint16_t* szProductBuf,
int32_t* pdwInstalledContext,
uint16_t* szSid,
uint32_t* pcchSid);
C, "msi.dll");
// $ffi->MsiEnumClientsExW(szComponent, szUserSid, dwContext, dwProductIndex, szProductBuf, pdwInstalledContext, szSid, pcchSid);
// szComponent : LPCWSTR
// szUserSid : LPCWSTR optional
// dwContext : DWORD
// dwProductIndex : DWORD
// szProductBuf : 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 MsiEnumClientsExW(
WString szComponent, // LPCWSTR
WString szUserSid, // LPCWSTR optional
int dwContext, // DWORD
int dwProductIndex, // DWORD
char[] szProductBuf, // 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 MsiEnumClientsExW = MsiEnumClientsExW(
szComponent : UInt16*, # LPCWSTR
szUserSid : UInt16*, # LPCWSTR optional
dwContext : UInt32, # DWORD
dwProductIndex : UInt32, # DWORD
szProductBuf : 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 MsiEnumClientsExWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiEnumClientsExWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Utf16>, Pointer<Int32>, Pointer<Utf16>, Pointer<Uint32>);
final MsiEnumClientsExW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiEnumClientsExWNative, MsiEnumClientsExWDart>('MsiEnumClientsExW');
// szComponent : LPCWSTR -> Pointer<Utf16>
// szUserSid : LPCWSTR optional -> Pointer<Utf16>
// dwContext : DWORD -> Uint32
// dwProductIndex : DWORD -> Uint32
// szProductBuf : 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 MsiEnumClientsExW(
szComponent: PWideChar; // LPCWSTR
szUserSid: PWideChar; // LPCWSTR optional
dwContext: DWORD; // DWORD
dwProductIndex: DWORD; // DWORD
szProductBuf: 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 'MsiEnumClientsExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiEnumClientsExW"
c_MsiEnumClientsExW :: CWString -> CWString -> Word32 -> Word32 -> CWString -> Ptr Int32 -> CWString -> Ptr Word32 -> IO Word32
-- szComponent : LPCWSTR -> CWString
-- szUserSid : LPCWSTR optional -> CWString
-- dwContext : DWORD -> Word32
-- dwProductIndex : DWORD -> Word32
-- szProductBuf : 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 msienumclientsexw =
foreign "MsiEnumClientsExW"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szComponent : LPCWSTR -> (ptr uint16_t) *)
(* szUserSid : LPCWSTR optional -> (ptr uint16_t) *)
(* dwContext : DWORD -> uint32_t *)
(* dwProductIndex : DWORD -> uint32_t *)
(* szProductBuf : 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 ("MsiEnumClientsExW" msi-enum-clients-ex-w :convention :stdcall) :uint32
(sz-component (:string :encoding :utf-16le)) ; LPCWSTR
(sz-user-sid (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-context :uint32) ; DWORD
(dw-product-index :uint32) ; DWORD
(sz-product-buf :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 $MsiEnumClientsExW = Win32::API::More->new('msi',
'DWORD MsiEnumClientsExW(LPCWSTR szComponent, LPCWSTR szUserSid, DWORD dwContext, DWORD dwProductIndex, LPWSTR szProductBuf, LPVOID pdwInstalledContext, LPWSTR szSid, LPVOID pcchSid)');
# my $ret = $MsiEnumClientsExW->Call($szComponent, $szUserSid, $dwContext, $dwProductIndex, $szProductBuf, $pdwInstalledContext, $szSid, $pcchSid);
# szComponent : LPCWSTR -> LPCWSTR
# szUserSid : LPCWSTR optional -> LPCWSTR
# dwContext : DWORD -> DWORD
# dwProductIndex : DWORD -> DWORD
# szProductBuf : 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 MsiEnumClientsExA (ANSI版) — コンテキストやユーザーを指定してコンポーネントのクライアント製品を列挙する。
- f MsiEnumClientsW — 指定コンポーネントを使用するクライアント製品を列挙する。