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