MsiProvideAssemblyW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiProvideAssemblyW(
LPCWSTR szAssemblyName,
LPCWSTR szAppContext, // optional
DWORD dwInstallMode,
MSIASSEMBLYINFO dwAssemblyInfo,
LPWSTR lpPathBuf, // optional
DWORD* pcchPathBuf // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| szAssemblyName | LPCWSTR | in | アセンブリ名を表す文字列です。 | ||||||||||||||
| szAppContext | LPCWSTR | inoptional | グローバルアセンブリの場合は null に設定します。プライベートアセンブリの場合は、szAppContext にアプリケーション構成ファイルのフルパス、またはそのアセンブリのプライベート対象であるアプリケーションの実行可能ファイルのフルパスを設定します。 | ||||||||||||||
| dwInstallMode | DWORD | in | インストールモードを定義します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||||
| dwAssemblyInfo | MSIASSEMBLYINFO | in | アセンブリ情報とアセンブリの種類です。次のいずれかの値を設定します。
| ||||||||||||||
| lpPathBuf | LPWSTR | outoptional | コンポーネントへのパスを受け取る変数へのポインターです。このパラメーターは null にできます。 | ||||||||||||||
| pcchPathBuf | DWORD* | inoutoptional | lpPathBuf パラメーターが指すバッファーのサイズ(文字数)を指定する変数へのポインターです。入力時には、終端の null 文字分の領域を含めたバッファーの全サイズを指定します。渡されたバッファーが小さすぎる場合、返される文字数には終端の null 文字は含まれません。 lpPathBuf が null の場合、pcchPathBuf も null にできます。 |
戻り値の型: DWORD
公式ドキュメント
MsiProvideAssembly 関数は、アセンブリを含む Windows Installer コンポーネントへのフルパスを返します。この関数はソースの入力を求め、必要なインストールを実行します。MsiProvideAssembly は機能の使用回数をインクリメントします。(Unicode)
戻り値
| 値 | 意味 |
|---|---|
| 構成データが破損しています。 | |
| 機能が存在しないか、破損しています。このエラーは dwInstallMode = INSTALLMODE_EXISTING の場合に返されます。 | |
| インストールに失敗しました。 | |
| 要求されたコンポーネントは、このコンピューター上で無効になっています。 | |
| 無効なパラメーターが関数に渡されました。 | |
| 関数は正常に完了しました。 | |
| 機能 ID が既知の機能を識別しません。 | |
| コンポーネント ID が既知のコンポーネントを指定していません。 | |
| 製品コードが既知の製品を識別しません。 | |
| 認識されない製品または機能名が関数に渡されました。 | |
| バッファーオーバーフローが返されました。 | |
| システムにこの操作を完了するための十分なメモリがありません。Windows Server 2003 で利用可能です。 | |
| ソースを検出できませんでした。 |
詳細については、 Displayed Error Messages を参照してください。
解説(Remarks)
MsiProvideAssembly 関数が成功すると、pcchPathBuf パラメーターには lpPathBuf 内の文字列の長さが格納されます。
INSTALLMODE_EXISTING オプションは REINSTALLMODE フラグと組み合わせて使用することはできません。
破損したファイルや誤ったバージョンのファイルを含むコンポーネントを持つ機能は、ユーザーが明示的に再インストールするか、アプリケーションから MsiReinstallFeature を呼び出して再インストールする必要があります。
msi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiProvideAssembly を定義しています。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在して使用すると、不整合が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiProvideAssemblyW(
LPCWSTR szAssemblyName,
LPCWSTR szAppContext, // optional
DWORD dwInstallMode,
MSIASSEMBLYINFO dwAssemblyInfo,
LPWSTR lpPathBuf, // optional
DWORD* pcchPathBuf // optional
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiProvideAssemblyW(
[MarshalAs(UnmanagedType.LPWStr)] string szAssemblyName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string szAppContext, // LPCWSTR optional
uint dwInstallMode, // DWORD
uint dwAssemblyInfo, // MSIASSEMBLYINFO
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf, // LPWSTR optional, out
IntPtr pcchPathBuf // DWORD* optional, in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiProvideAssemblyW(
<MarshalAs(UnmanagedType.LPWStr)> szAssemblyName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> szAppContext As String, ' LPCWSTR optional
dwInstallMode As UInteger, ' DWORD
dwAssemblyInfo As UInteger, ' MSIASSEMBLYINFO
<MarshalAs(UnmanagedType.LPWStr)> lpPathBuf As System.Text.StringBuilder, ' LPWSTR optional, out
pcchPathBuf As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' szAssemblyName : LPCWSTR
' szAppContext : LPCWSTR optional
' dwInstallMode : DWORD
' dwAssemblyInfo : MSIASSEMBLYINFO
' lpPathBuf : LPWSTR optional, out
' pcchPathBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiProvideAssemblyW Lib "msi" ( _
ByVal szAssemblyName As LongPtr, _
ByVal szAppContext As LongPtr, _
ByVal dwInstallMode As Long, _
ByVal dwAssemblyInfo As Long, _
ByVal lpPathBuf As LongPtr, _
ByVal pcchPathBuf 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
MsiProvideAssemblyW = ctypes.windll.msi.MsiProvideAssemblyW
MsiProvideAssemblyW.restype = wintypes.DWORD
MsiProvideAssemblyW.argtypes = [
wintypes.LPCWSTR, # szAssemblyName : LPCWSTR
wintypes.LPCWSTR, # szAppContext : LPCWSTR optional
wintypes.DWORD, # dwInstallMode : DWORD
wintypes.DWORD, # dwAssemblyInfo : MSIASSEMBLYINFO
wintypes.LPWSTR, # lpPathBuf : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchPathBuf : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiProvideAssemblyW = Fiddle::Function.new(
lib['MsiProvideAssemblyW'],
[
Fiddle::TYPE_VOIDP, # szAssemblyName : LPCWSTR
Fiddle::TYPE_VOIDP, # szAppContext : LPCWSTR optional
-Fiddle::TYPE_INT, # dwInstallMode : DWORD
-Fiddle::TYPE_INT, # dwAssemblyInfo : MSIASSEMBLYINFO
Fiddle::TYPE_VOIDP, # lpPathBuf : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # pcchPathBuf : DWORD* optional, in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiProvideAssemblyW(
szAssemblyName: *const u16, // LPCWSTR
szAppContext: *const u16, // LPCWSTR optional
dwInstallMode: u32, // DWORD
dwAssemblyInfo: u32, // MSIASSEMBLYINFO
lpPathBuf: *mut u16, // LPWSTR optional, out
pcchPathBuf: *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 MsiProvideAssemblyW([MarshalAs(UnmanagedType.LPWStr)] string szAssemblyName, [MarshalAs(UnmanagedType.LPWStr)] string szAppContext, uint dwInstallMode, uint dwAssemblyInfo, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpPathBuf, IntPtr pcchPathBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiProvideAssemblyW' -Namespace Win32 -PassThru
# $api::MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)#uselib "msi.dll"
#func global MsiProvideAssemblyW "MsiProvideAssemblyW" wptr, wptr, wptr, wptr, wptr, wptr
; MsiProvideAssemblyW szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, varptr(lpPathBuf), varptr(pcchPathBuf) ; 戻り値は stat
; szAssemblyName : LPCWSTR -> "wptr"
; szAppContext : LPCWSTR optional -> "wptr"
; dwInstallMode : DWORD -> "wptr"
; dwAssemblyInfo : MSIASSEMBLYINFO -> "wptr"
; lpPathBuf : LPWSTR optional, out -> "wptr"
; pcchPathBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiProvideAssemblyW "MsiProvideAssemblyW" wstr, wstr, int, int, var, var ; res = MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf) ; szAssemblyName : LPCWSTR -> "wstr" ; szAppContext : LPCWSTR optional -> "wstr" ; dwInstallMode : DWORD -> "int" ; dwAssemblyInfo : MSIASSEMBLYINFO -> "int" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiProvideAssemblyW "MsiProvideAssemblyW" wstr, wstr, int, int, sptr, sptr ; res = MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, varptr(lpPathBuf), varptr(pcchPathBuf)) ; szAssemblyName : LPCWSTR -> "wstr" ; szAppContext : LPCWSTR optional -> "wstr" ; dwInstallMode : DWORD -> "int" ; dwAssemblyInfo : MSIASSEMBLYINFO -> "int" ; lpPathBuf : LPWSTR optional, out -> "sptr" ; pcchPathBuf : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiProvideAssemblyW(LPCWSTR szAssemblyName, LPCWSTR szAppContext, DWORD dwInstallMode, MSIASSEMBLYINFO dwAssemblyInfo, LPWSTR lpPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiProvideAssemblyW "MsiProvideAssemblyW" wstr, wstr, int, int, var, var ; res = MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf) ; szAssemblyName : LPCWSTR -> "wstr" ; szAppContext : LPCWSTR optional -> "wstr" ; dwInstallMode : DWORD -> "int" ; dwAssemblyInfo : MSIASSEMBLYINFO -> "int" ; lpPathBuf : LPWSTR optional, out -> "var" ; pcchPathBuf : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiProvideAssemblyW(LPCWSTR szAssemblyName, LPCWSTR szAppContext, DWORD dwInstallMode, MSIASSEMBLYINFO dwAssemblyInfo, LPWSTR lpPathBuf, DWORD* pcchPathBuf) #uselib "msi.dll" #cfunc global MsiProvideAssemblyW "MsiProvideAssemblyW" wstr, wstr, int, int, intptr, intptr ; res = MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, varptr(lpPathBuf), varptr(pcchPathBuf)) ; szAssemblyName : LPCWSTR -> "wstr" ; szAppContext : LPCWSTR optional -> "wstr" ; dwInstallMode : DWORD -> "int" ; dwAssemblyInfo : MSIASSEMBLYINFO -> "int" ; lpPathBuf : LPWSTR optional, out -> "intptr" ; pcchPathBuf : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiProvideAssemblyW = msi.NewProc("MsiProvideAssemblyW")
)
// szAssemblyName (LPCWSTR), szAppContext (LPCWSTR optional), dwInstallMode (DWORD), dwAssemblyInfo (MSIASSEMBLYINFO), lpPathBuf (LPWSTR optional, out), pcchPathBuf (DWORD* optional, in/out)
r1, _, err := procMsiProvideAssemblyW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szAssemblyName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szAppContext))),
uintptr(dwInstallMode),
uintptr(dwAssemblyInfo),
uintptr(lpPathBuf),
uintptr(pcchPathBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiProvideAssemblyW(
szAssemblyName: PWideChar; // LPCWSTR
szAppContext: PWideChar; // LPCWSTR optional
dwInstallMode: DWORD; // DWORD
dwAssemblyInfo: DWORD; // MSIASSEMBLYINFO
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiProvideAssemblyW';result := DllCall("msi\MsiProvideAssemblyW"
, "WStr", szAssemblyName ; LPCWSTR
, "WStr", szAppContext ; LPCWSTR optional
, "UInt", dwInstallMode ; DWORD
, "UInt", dwAssemblyInfo ; MSIASSEMBLYINFO
, "Ptr", lpPathBuf ; LPWSTR optional, out
, "Ptr", pcchPathBuf ; DWORD* optional, in/out
, "UInt") ; return: DWORD●MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf) = DLL("msi.dll", "dword MsiProvideAssemblyW(char*, char*, dword, dword, char*, void*)")
# 呼び出し: MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)
# szAssemblyName : LPCWSTR -> "char*"
# szAppContext : LPCWSTR optional -> "char*"
# dwInstallMode : DWORD -> "dword"
# dwAssemblyInfo : MSIASSEMBLYINFO -> "dword"
# lpPathBuf : LPWSTR optional, out -> "char*"
# pcchPathBuf : 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 MsiProvideAssemblyW(
szAssemblyName: [*c]const u16, // LPCWSTR
szAppContext: [*c]const u16, // LPCWSTR optional
dwInstallMode: u32, // DWORD
dwAssemblyInfo: u32, // MSIASSEMBLYINFO
lpPathBuf: [*c]u16, // LPWSTR optional, out
pcchPathBuf: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiProvideAssemblyW(
szAssemblyName: WideCString, # LPCWSTR
szAppContext: WideCString, # LPCWSTR optional
dwInstallMode: uint32, # DWORD
dwAssemblyInfo: uint32, # MSIASSEMBLYINFO
lpPathBuf: ptr uint16, # LPWSTR optional, out
pcchPathBuf: ptr uint32 # DWORD* optional, in/out
): uint32 {.importc: "MsiProvideAssemblyW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiProvideAssemblyW(
const(wchar)* szAssemblyName, // LPCWSTR
const(wchar)* szAppContext, // LPCWSTR optional
uint dwInstallMode, // DWORD
uint dwAssemblyInfo, // MSIASSEMBLYINFO
wchar* lpPathBuf, // LPWSTR optional, out
uint* pcchPathBuf // DWORD* optional, in/out
);ccall((:MsiProvideAssemblyW, "msi.dll"), stdcall, UInt32,
(Cwstring, Cwstring, UInt32, UInt32, Ptr{UInt16}, Ptr{UInt32}),
szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)
# szAssemblyName : LPCWSTR -> Cwstring
# szAppContext : LPCWSTR optional -> Cwstring
# dwInstallMode : DWORD -> UInt32
# dwAssemblyInfo : MSIASSEMBLYINFO -> UInt32
# lpPathBuf : LPWSTR optional, out -> Ptr{UInt16}
# pcchPathBuf : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiProvideAssemblyW(
const uint16_t* szAssemblyName,
const uint16_t* szAppContext,
uint32_t dwInstallMode,
uint32_t dwAssemblyInfo,
uint16_t* lpPathBuf,
uint32_t* pcchPathBuf);
]]
local msi = ffi.load("msi")
-- msi.MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)
-- szAssemblyName : LPCWSTR
-- szAppContext : LPCWSTR optional
-- dwInstallMode : DWORD
-- dwAssemblyInfo : MSIASSEMBLYINFO
-- lpPathBuf : LPWSTR optional, out
-- pcchPathBuf : 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 MsiProvideAssemblyW = lib.func('__stdcall', 'MsiProvideAssemblyW', 'uint32_t', ['str16', 'str16', 'uint32_t', 'uint32_t', 'uint16_t *', 'uint32_t *']);
// MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)
// szAssemblyName : LPCWSTR -> 'str16'
// szAppContext : LPCWSTR optional -> 'str16'
// dwInstallMode : DWORD -> 'uint32_t'
// dwAssemblyInfo : MSIASSEMBLYINFO -> 'uint32_t'
// lpPathBuf : LPWSTR optional, out -> 'uint16_t *'
// pcchPathBuf : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiProvideAssemblyW: { parameters: ["buffer", "buffer", "u32", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf)
// szAssemblyName : LPCWSTR -> "buffer"
// szAppContext : LPCWSTR optional -> "buffer"
// dwInstallMode : DWORD -> "u32"
// dwAssemblyInfo : MSIASSEMBLYINFO -> "u32"
// lpPathBuf : LPWSTR optional, out -> "buffer"
// pcchPathBuf : 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 MsiProvideAssemblyW(
const uint16_t* szAssemblyName,
const uint16_t* szAppContext,
uint32_t dwInstallMode,
uint32_t dwAssemblyInfo,
uint16_t* lpPathBuf,
uint32_t* pcchPathBuf);
C, "msi.dll");
// $ffi->MsiProvideAssemblyW(szAssemblyName, szAppContext, dwInstallMode, dwAssemblyInfo, lpPathBuf, pcchPathBuf);
// szAssemblyName : LPCWSTR
// szAppContext : LPCWSTR optional
// dwInstallMode : DWORD
// dwAssemblyInfo : MSIASSEMBLYINFO
// lpPathBuf : LPWSTR optional, out
// pcchPathBuf : 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 MsiProvideAssemblyW(
WString szAssemblyName, // LPCWSTR
WString szAppContext, // LPCWSTR optional
int dwInstallMode, // DWORD
int dwAssemblyInfo, // MSIASSEMBLYINFO
char[] lpPathBuf, // LPWSTR optional, out
IntByReference pcchPathBuf // DWORD* optional, in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiProvideAssemblyW = MsiProvideAssemblyW(
szAssemblyName : UInt16*, # LPCWSTR
szAppContext : UInt16*, # LPCWSTR optional
dwInstallMode : UInt32, # DWORD
dwAssemblyInfo : UInt32, # MSIASSEMBLYINFO
lpPathBuf : UInt16*, # LPWSTR optional, out
pcchPathBuf : 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 MsiProvideAssemblyWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef MsiProvideAssemblyWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Utf16>, Pointer<Uint32>);
final MsiProvideAssemblyW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiProvideAssemblyWNative, MsiProvideAssemblyWDart>('MsiProvideAssemblyW');
// szAssemblyName : LPCWSTR -> Pointer<Utf16>
// szAppContext : LPCWSTR optional -> Pointer<Utf16>
// dwInstallMode : DWORD -> Uint32
// dwAssemblyInfo : MSIASSEMBLYINFO -> Uint32
// lpPathBuf : LPWSTR optional, out -> Pointer<Utf16>
// pcchPathBuf : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiProvideAssemblyW(
szAssemblyName: PWideChar; // LPCWSTR
szAppContext: PWideChar; // LPCWSTR optional
dwInstallMode: DWORD; // DWORD
dwAssemblyInfo: DWORD; // MSIASSEMBLYINFO
lpPathBuf: PWideChar; // LPWSTR optional, out
pcchPathBuf: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiProvideAssemblyW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiProvideAssemblyW"
c_MsiProvideAssemblyW :: CWString -> CWString -> Word32 -> Word32 -> CWString -> Ptr Word32 -> IO Word32
-- szAssemblyName : LPCWSTR -> CWString
-- szAppContext : LPCWSTR optional -> CWString
-- dwInstallMode : DWORD -> Word32
-- dwAssemblyInfo : MSIASSEMBLYINFO -> Word32
-- lpPathBuf : LPWSTR optional, out -> CWString
-- pcchPathBuf : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msiprovideassemblyw =
foreign "MsiProvideAssemblyW"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* szAssemblyName : LPCWSTR -> (ptr uint16_t) *)
(* szAppContext : LPCWSTR optional -> (ptr uint16_t) *)
(* dwInstallMode : DWORD -> uint32_t *)
(* dwAssemblyInfo : MSIASSEMBLYINFO -> uint32_t *)
(* lpPathBuf : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchPathBuf : 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 ("MsiProvideAssemblyW" msi-provide-assembly-w :convention :stdcall) :uint32
(sz-assembly-name (:string :encoding :utf-16le)) ; LPCWSTR
(sz-app-context (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-install-mode :uint32) ; DWORD
(dw-assembly-info :uint32) ; MSIASSEMBLYINFO
(lp-path-buf :pointer) ; LPWSTR optional, out
(pcch-path-buf :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiProvideAssemblyW = Win32::API::More->new('msi',
'DWORD MsiProvideAssemblyW(LPCWSTR szAssemblyName, LPCWSTR szAppContext, DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf, LPVOID pcchPathBuf)');
# my $ret = $MsiProvideAssemblyW->Call($szAssemblyName, $szAppContext, $dwInstallMode, $dwAssemblyInfo, $lpPathBuf, $pcchPathBuf);
# szAssemblyName : LPCWSTR -> LPCWSTR
# szAppContext : LPCWSTR optional -> LPCWSTR
# dwInstallMode : DWORD -> DWORD
# dwAssemblyInfo : MSIASSEMBLYINFO -> DWORD
# lpPathBuf : LPWSTR optional, out -> LPWSTR
# pcchPathBuf : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiProvideAssemblyA (ANSI版) — 指定したアセンブリのパスを取得し、必要なら起動時にインストールする。