MsiGetFeatureCostW
関数シグネチャ
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetFeatureCostW(
MSIHANDLE hInstall,
LPCWSTR szFeature,
MSICOSTTREE iCostTree,
INSTALLSTATE iState,
INT* piCost
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに渡される、または MsiOpenPackage、MsiOpenPackageEx、MsiOpenProduct によって取得されるインストールのハンドルです。 | ||||||||||||
| szFeature | LPCWSTR | in | 機能の名前を指定します。 | ||||||||||||
| iCostTree | MSICOSTTREE | in | ディスク領域の要件を判定するために関数が使用する値を指定します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| iState | INSTALLSTATE | in | インストール状態を指定します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| piCost | INT* | inout | 512 バイト単位でディスク領域の要件を受け取ります。このパラメーターを null にすることはできません。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetFeatureCost 関数は、ある機能と、選択されたその子機能および親機能が必要とするディスク領域を返します。(Unicode)
戻り値
MsiGetFeatureCost 関数は次の値を返します:
解説(Remarks)
Calling Database Functions From Programs を参照してください。
MsiGetFeatureCost 関数において、MSICOSTTREE_SELFONLY 値は、指定した機能のみが必要とするディスク領域の合計(512 バイト単位)を示します。この戻り値には、指定した機能の子機能や親機能は含まれません。この合計コストは、その機能にリンクされたすべてのコンポーネントに割り当てられたディスクコストで構成されます。
MSICOSTTREE_CHILDREN 値は、指定した機能とその子機能が必要とするディスク領域の合計(512 バイト単位)を示します。各機能について、合計コストはその機能にリンクされたすべてのコンポーネントに割り当てられたディスクコストで構成されます。
MSICOSTTREE_PARENTS 値は、指定した機能とその親機能(Feature テーブルのルートまで)が必要とするディスク領域の合計(512 バイト単位)を示します。各機能について、合計コストはその機能にリンクされたすべてのコンポーネントに割り当てられたディスクコストで構成されます。
MsiGetFeatureCost が成功するには、他のいくつかの関数に依存します。次の例は、これらの関数を呼び出さなければならない順序を示しています:
MSIHANDLE hInstall; //product handle, must be closed
int iCost; //cost returned by MsiGetFeatureCost
MsiOpenPackage("Path to package....",&hInstall); //"Path to package...." should be replaced with the full path to the package to be opened
MsiDoAction(hInstall,"CostInitialize"); //
MsiDoAction(hInstall,"FileCost");
MsiDoAction(hInstall,"CostFinalize");
MsiDoAction(hInstall,"InstallValidate");
MsiGetFeatureCost(hInstall,"FeatureName",MSICOSTTREE_SELFONLY,INSTALLSTATE_ABSENT,&iCost);
MsiCloseHandle(hInstall); //close the open product handle
削除予定の機能のコストを照会する処理は、わずかに異なります:
MSIHANDLE hInstall; //product handle, must be closed
int iCost; //cost returned by MsiGetFeatureCost
MsiOpenPackage("Path to package....",&hInstall); //"Path to package...." should be replaced with the full path to the package to be opened
MsiDoAction(hInstall,"CostInitialize"); //
MsiDoAction(hInstall,"FileCost");
MsiDoAction(hInstall,"CostFinalize");
MsiSetFeatureState(hInstall,"FeatureName",INSTALLSTATE_ABSENT); //set the feature's state to "not installed"
MsiDoAction(hInstall,"InstallValidate");
MsiGetFeatureCost(hInstall,"FeatureName",MSICOSTTREE_SELFONLY,INSTALLSTATE_ABSENT,&iCost);
MsiCloseHandle(hInstall); //close the open product handle
関数が失敗した場合、MsiGetLastErrorRecord を使用して拡張エラー情報を取得できます。
msiquery.h ヘッダーは、UNICODE プリプロセッサー定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして MsiGetFeatureCost を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (Unicode / -W)
#include <windows.h>
DWORD MsiGetFeatureCostW(
MSIHANDLE hInstall,
LPCWSTR szFeature,
MSICOSTTREE iCostTree,
INSTALLSTATE iState,
INT* piCost
);[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetFeatureCostW(
uint hInstall, // MSIHANDLE
[MarshalAs(UnmanagedType.LPWStr)] string szFeature, // LPCWSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
ref int piCost // INT* in/out
);<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetFeatureCostW(
hInstall As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPWStr)> szFeature As String, ' LPCWSTR
iCostTree As Integer, ' MSICOSTTREE
iState As Integer, ' INSTALLSTATE
ByRef piCost As Integer ' INT* in/out
) As UInteger
End Function' hInstall : MSIHANDLE
' szFeature : LPCWSTR
' iCostTree : MSICOSTTREE
' iState : INSTALLSTATE
' piCost : INT* in/out
Declare PtrSafe Function MsiGetFeatureCostW Lib "msi" ( _
ByVal hInstall As Long, _
ByVal szFeature As LongPtr, _
ByVal iCostTree As Long, _
ByVal iState As Long, _
ByRef piCost As Long) 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
MsiGetFeatureCostW = ctypes.windll.msi.MsiGetFeatureCostW
MsiGetFeatureCostW.restype = wintypes.DWORD
MsiGetFeatureCostW.argtypes = [
wintypes.DWORD, # hInstall : MSIHANDLE
wintypes.LPCWSTR, # szFeature : LPCWSTR
ctypes.c_int, # iCostTree : MSICOSTTREE
ctypes.c_int, # iState : INSTALLSTATE
ctypes.POINTER(ctypes.c_int), # piCost : INT* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('msi.dll')
MsiGetFeatureCostW = Fiddle::Function.new(
lib['MsiGetFeatureCostW'],
[
-Fiddle::TYPE_INT, # hInstall : MSIHANDLE
Fiddle::TYPE_VOIDP, # szFeature : LPCWSTR
Fiddle::TYPE_INT, # iCostTree : MSICOSTTREE
Fiddle::TYPE_INT, # iState : INSTALLSTATE
Fiddle::TYPE_VOIDP, # piCost : INT* in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "msi")]
extern "system" {
fn MsiGetFeatureCostW(
hInstall: u32, // MSIHANDLE
szFeature: *const u16, // LPCWSTR
iCostTree: i32, // MSICOSTTREE
iState: i32, // INSTALLSTATE
piCost: *mut i32 // INT* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetFeatureCostW(uint hInstall, [MarshalAs(UnmanagedType.LPWStr)] string szFeature, int iCostTree, int iState, ref int piCost);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFeatureCostW' -Namespace Win32 -PassThru
# $api::MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost)#uselib "msi.dll"
#func global MsiGetFeatureCostW "MsiGetFeatureCostW" wptr, wptr, wptr, wptr, wptr
; MsiGetFeatureCostW hInstall, szFeature, iCostTree, iState, varptr(piCost) ; 戻り値は stat
; hInstall : MSIHANDLE -> "wptr"
; szFeature : LPCWSTR -> "wptr"
; iCostTree : MSICOSTTREE -> "wptr"
; iState : INSTALLSTATE -> "wptr"
; piCost : INT* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetFeatureCostW "MsiGetFeatureCostW" int, wstr, int, int, var ; res = MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCWSTR -> "wstr" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetFeatureCostW "MsiGetFeatureCostW" int, wstr, int, int, sptr ; res = MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, varptr(piCost)) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCWSTR -> "wstr" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature, MSICOSTTREE iCostTree, INSTALLSTATE iState, INT* piCost) #uselib "msi.dll" #cfunc global MsiGetFeatureCostW "MsiGetFeatureCostW" int, wstr, int, int, var ; res = MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCWSTR -> "wstr" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature, MSICOSTTREE iCostTree, INSTALLSTATE iState, INT* piCost) #uselib "msi.dll" #cfunc global MsiGetFeatureCostW "MsiGetFeatureCostW" int, wstr, int, int, intptr ; res = MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, varptr(piCost)) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCWSTR -> "wstr" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
msi = windows.NewLazySystemDLL("msi.dll")
procMsiGetFeatureCostW = msi.NewProc("MsiGetFeatureCostW")
)
// hInstall (MSIHANDLE), szFeature (LPCWSTR), iCostTree (MSICOSTTREE), iState (INSTALLSTATE), piCost (INT* in/out)
r1, _, err := procMsiGetFeatureCostW.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFeature))),
uintptr(iCostTree),
uintptr(iState),
uintptr(piCost),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetFeatureCostW(
hInstall: DWORD; // MSIHANDLE
szFeature: PWideChar; // LPCWSTR
iCostTree: Integer; // MSICOSTTREE
iState: Integer; // INSTALLSTATE
piCost: Pointer // INT* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetFeatureCostW';result := DllCall("msi\MsiGetFeatureCostW"
, "UInt", hInstall ; MSIHANDLE
, "WStr", szFeature ; LPCWSTR
, "Int", iCostTree ; MSICOSTTREE
, "Int", iState ; INSTALLSTATE
, "Ptr", piCost ; INT* in/out
, "UInt") ; return: DWORD●MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost) = DLL("msi.dll", "dword MsiGetFeatureCostW(dword, char*, int, int, void*)")
# 呼び出し: MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost)
# hInstall : MSIHANDLE -> "dword"
# szFeature : LPCWSTR -> "char*"
# iCostTree : MSICOSTTREE -> "int"
# iState : INSTALLSTATE -> "int"
# piCost : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "msi" fn MsiGetFeatureCostW(
hInstall: u32, // MSIHANDLE
szFeature: [*c]const u16, // LPCWSTR
iCostTree: i32, // MSICOSTTREE
iState: i32, // INSTALLSTATE
piCost: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc MsiGetFeatureCostW(
hInstall: uint32, # MSIHANDLE
szFeature: WideCString, # LPCWSTR
iCostTree: int32, # MSICOSTTREE
iState: int32, # INSTALLSTATE
piCost: ptr int32 # INT* in/out
): uint32 {.importc: "MsiGetFeatureCostW", stdcall, dynlib: "msi.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "msi");
extern(Windows)
uint MsiGetFeatureCostW(
uint hInstall, // MSIHANDLE
const(wchar)* szFeature, // LPCWSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
int* piCost // INT* in/out
);ccall((:MsiGetFeatureCostW, "msi.dll"), stdcall, UInt32,
(UInt32, Cwstring, Int32, Int32, Ptr{Int32}),
hInstall, szFeature, iCostTree, iState, piCost)
# hInstall : MSIHANDLE -> UInt32
# szFeature : LPCWSTR -> Cwstring
# iCostTree : MSICOSTTREE -> Int32
# iState : INSTALLSTATE -> Int32
# piCost : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetFeatureCostW(
uint32_t hInstall,
const uint16_t* szFeature,
int32_t iCostTree,
int32_t iState,
int32_t* piCost);
]]
local msi = ffi.load("msi")
-- msi.MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost)
-- hInstall : MSIHANDLE
-- szFeature : LPCWSTR
-- iCostTree : MSICOSTTREE
-- iState : INSTALLSTATE
-- piCost : INT* 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 MsiGetFeatureCostW = lib.func('__stdcall', 'MsiGetFeatureCostW', 'uint32_t', ['uint32_t', 'str16', 'int32_t', 'int32_t', 'int32_t *']);
// MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost)
// hInstall : MSIHANDLE -> 'uint32_t'
// szFeature : LPCWSTR -> 'str16'
// iCostTree : MSICOSTTREE -> 'int32_t'
// iState : INSTALLSTATE -> 'int32_t'
// piCost : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetFeatureCostW: { parameters: ["u32", "buffer", "i32", "i32", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost)
// hInstall : MSIHANDLE -> "u32"
// szFeature : LPCWSTR -> "buffer"
// iCostTree : MSICOSTTREE -> "i32"
// iState : INSTALLSTATE -> "i32"
// piCost : INT* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetFeatureCostW(
uint32_t hInstall,
const uint16_t* szFeature,
int32_t iCostTree,
int32_t iState,
int32_t* piCost);
C, "msi.dll");
// $ffi->MsiGetFeatureCostW(hInstall, szFeature, iCostTree, iState, piCost);
// hInstall : MSIHANDLE
// szFeature : LPCWSTR
// iCostTree : MSICOSTTREE
// iState : INSTALLSTATE
// piCost : INT* 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 MsiGetFeatureCostW(
int hInstall, // MSIHANDLE
WString szFeature, // LPCWSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
IntByReference piCost // INT* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("msi")]
lib Libmsi
fun MsiGetFeatureCostW = MsiGetFeatureCostW(
hInstall : UInt32, # MSIHANDLE
szFeature : UInt16*, # LPCWSTR
iCostTree : Int32, # MSICOSTTREE
iState : Int32, # INSTALLSTATE
piCost : Int32* # INT* 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 MsiGetFeatureCostWNative = Uint32 Function(Uint32, Pointer<Utf16>, Int32, Int32, Pointer<Int32>);
typedef MsiGetFeatureCostWDart = int Function(int, Pointer<Utf16>, int, int, Pointer<Int32>);
final MsiGetFeatureCostW = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetFeatureCostWNative, MsiGetFeatureCostWDart>('MsiGetFeatureCostW');
// hInstall : MSIHANDLE -> Uint32
// szFeature : LPCWSTR -> Pointer<Utf16>
// iCostTree : MSICOSTTREE -> Int32
// iState : INSTALLSTATE -> Int32
// piCost : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetFeatureCostW(
hInstall: DWORD; // MSIHANDLE
szFeature: PWideChar; // LPCWSTR
iCostTree: Integer; // MSICOSTTREE
iState: Integer; // INSTALLSTATE
piCost: Pointer // INT* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetFeatureCostW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetFeatureCostW"
c_MsiGetFeatureCostW :: Word32 -> CWString -> Int32 -> Int32 -> Ptr Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szFeature : LPCWSTR -> CWString
-- iCostTree : MSICOSTTREE -> Int32
-- iState : INSTALLSTATE -> Int32
-- piCost : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetfeaturecostw =
foreign "MsiGetFeatureCostW"
(uint32_t @-> (ptr uint16_t) @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szFeature : LPCWSTR -> (ptr uint16_t) *)
(* iCostTree : MSICOSTTREE -> int32_t *)
(* iState : INSTALLSTATE -> int32_t *)
(* piCost : INT* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library msi (t "msi.dll"))
(cffi:use-foreign-library msi)
(cffi:defcfun ("MsiGetFeatureCostW" msi-get-feature-cost-w :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-feature (:string :encoding :utf-16le)) ; LPCWSTR
(i-cost-tree :int32) ; MSICOSTTREE
(i-state :int32) ; INSTALLSTATE
(pi-cost :pointer)) ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MsiGetFeatureCostW = Win32::API::More->new('msi',
'DWORD MsiGetFeatureCostW(DWORD hInstall, LPCWSTR szFeature, int iCostTree, int iState, LPVOID piCost)');
# my $ret = $MsiGetFeatureCostW->Call($hInstall, $szFeature, $iCostTree, $iState, $piCost);
# hInstall : MSIHANDLE -> DWORD
# szFeature : LPCWSTR -> LPCWSTR
# iCostTree : MSICOSTTREE -> int
# iState : INSTALLSTATE -> int
# piCost : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f MsiGetFeatureCostA (ANSI版) — 機能のインストールに必要なディスク容量コストを取得する(ANSI版)。