MsiGetFeatureCostA
関数シグネチャ
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetFeatureCostA(
MSIHANDLE hInstall,
LPCSTR szFeature,
MSICOSTTREE iCostTree,
INSTALLSTATE iState,
INT* piCost
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hInstall | MSIHANDLE | in | DLL カスタムアクションに渡されたインストールのハンドル、または MsiOpenPackage、MsiOpenPackageEx、MsiOpenProduct によって取得したハンドルを指定します。 | ||||||||||||
| szFeature | LPCSTR | in | 機能の名前を指定します。 | ||||||||||||
| iCostTree | MSICOSTTREE | in | この関数がディスク領域要件を判定するために使用する値を指定します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| iState | INSTALLSTATE | in | インストール状態を指定します。このパラメーターには次のいずれかの値を指定できます。
| ||||||||||||
| piCost | INT* | inout | ディスク領域要件を 512 バイト単位で受け取ります。このパラメーターを null にすることはできません。 |
戻り値の型: DWORD
公式ドキュメント
MsiGetFeatureCost 関数は、ある機能 (feature) と、選択されたその子機能および親機能が必要とするディスク領域を返します。(ANSI)
戻り値
MsiGetFeatureCost 関数は次の値を返します。
解説(Remarks)
Calling Database Functions From Programs を参照してください。
MsiGetFeatureCost 関数において、MSICOSTTREE_SELFONLY 値は、指定した機能のみが必要とするディスク領域の総量 (512 バイト単位) を示します。この戻り値には、指定した機能の子機能や親機能は含まれません。この総コストは、その機能にリンクされたすべてのコンポーネントに割り当てられたディスクコストで構成されます。
MSICOSTTREE_CHILDREN 値は、指定した機能とその子機能が必要とするディスク領域の総量 (512 バイト単位) を示します。各機能について、総コストは、その機能にリンクされたすべてのコンポーネントに割り当てられたディスクコストで構成されます。
MSICOSTTREE_PARENTS 値は、指定した機能とその親機能 (Feature table のルートまで) が必要とするディスク領域の総量 (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 ヘッダーは、MsiGetFeatureCost を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードとを混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// msi.dll (ANSI / -A)
#include <windows.h>
DWORD MsiGetFeatureCostA(
MSIHANDLE hInstall,
LPCSTR szFeature,
MSICOSTTREE iCostTree,
INSTALLSTATE iState,
INT* piCost
);[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetFeatureCostA(
uint hInstall, // MSIHANDLE
[MarshalAs(UnmanagedType.LPStr)] string szFeature, // LPCSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
ref int piCost // INT* in/out
);<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetFeatureCostA(
hInstall As UInteger, ' MSIHANDLE
<MarshalAs(UnmanagedType.LPStr)> szFeature As String, ' LPCSTR
iCostTree As Integer, ' MSICOSTTREE
iState As Integer, ' INSTALLSTATE
ByRef piCost As Integer ' INT* in/out
) As UInteger
End Function' hInstall : MSIHANDLE
' szFeature : LPCSTR
' iCostTree : MSICOSTTREE
' iState : INSTALLSTATE
' piCost : INT* in/out
Declare PtrSafe Function MsiGetFeatureCostA Lib "msi" ( _
ByVal hInstall As Long, _
ByVal szFeature As String, _
ByVal iCostTree As Long, _
ByVal iState As Long, _
ByRef piCost As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MsiGetFeatureCostA = ctypes.windll.msi.MsiGetFeatureCostA
MsiGetFeatureCostA.restype = wintypes.DWORD
MsiGetFeatureCostA.argtypes = [
wintypes.DWORD, # hInstall : MSIHANDLE
wintypes.LPCSTR, # szFeature : LPCSTR
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')
MsiGetFeatureCostA = Fiddle::Function.new(
lib['MsiGetFeatureCostA'],
[
-Fiddle::TYPE_INT, # hInstall : MSIHANDLE
Fiddle::TYPE_VOIDP, # szFeature : LPCSTR
Fiddle::TYPE_INT, # iCostTree : MSICOSTTREE
Fiddle::TYPE_INT, # iState : INSTALLSTATE
Fiddle::TYPE_VOIDP, # piCost : INT* in/out
],
-Fiddle::TYPE_INT)#[link(name = "msi")]
extern "system" {
fn MsiGetFeatureCostA(
hInstall: u32, // MSIHANDLE
szFeature: *const u8, // LPCSTR
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.Ansi)]
public static extern uint MsiGetFeatureCostA(uint hInstall, [MarshalAs(UnmanagedType.LPStr)] string szFeature, int iCostTree, int iState, ref int piCost);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFeatureCostA' -Namespace Win32 -PassThru
# $api::MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost)#uselib "msi.dll"
#func global MsiGetFeatureCostA "MsiGetFeatureCostA" sptr, sptr, sptr, sptr, sptr
; MsiGetFeatureCostA hInstall, szFeature, iCostTree, iState, varptr(piCost) ; 戻り値は stat
; hInstall : MSIHANDLE -> "sptr"
; szFeature : LPCSTR -> "sptr"
; iCostTree : MSICOSTTREE -> "sptr"
; iState : INSTALLSTATE -> "sptr"
; piCost : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "msi.dll" #cfunc global MsiGetFeatureCostA "MsiGetFeatureCostA" int, str, int, int, var ; res = MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCSTR -> "str" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "msi.dll" #cfunc global MsiGetFeatureCostA "MsiGetFeatureCostA" int, str, int, int, sptr ; res = MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, varptr(piCost)) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCSTR -> "str" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature, MSICOSTTREE iCostTree, INSTALLSTATE iState, INT* piCost) #uselib "msi.dll" #cfunc global MsiGetFeatureCostA "MsiGetFeatureCostA" int, str, int, int, var ; res = MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCSTR -> "str" ; iCostTree : MSICOSTTREE -> "int" ; iState : INSTALLSTATE -> "int" ; piCost : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature, MSICOSTTREE iCostTree, INSTALLSTATE iState, INT* piCost) #uselib "msi.dll" #cfunc global MsiGetFeatureCostA "MsiGetFeatureCostA" int, str, int, int, intptr ; res = MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, varptr(piCost)) ; hInstall : MSIHANDLE -> "int" ; szFeature : LPCSTR -> "str" ; 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")
procMsiGetFeatureCostA = msi.NewProc("MsiGetFeatureCostA")
)
// hInstall (MSIHANDLE), szFeature (LPCSTR), iCostTree (MSICOSTTREE), iState (INSTALLSTATE), piCost (INT* in/out)
r1, _, err := procMsiGetFeatureCostA.Call(
uintptr(hInstall),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szFeature))),
uintptr(iCostTree),
uintptr(iState),
uintptr(piCost),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction MsiGetFeatureCostA(
hInstall: DWORD; // MSIHANDLE
szFeature: PAnsiChar; // LPCSTR
iCostTree: Integer; // MSICOSTTREE
iState: Integer; // INSTALLSTATE
piCost: Pointer // INT* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetFeatureCostA';result := DllCall("msi\MsiGetFeatureCostA"
, "UInt", hInstall ; MSIHANDLE
, "AStr", szFeature ; LPCSTR
, "Int", iCostTree ; MSICOSTTREE
, "Int", iState ; INSTALLSTATE
, "Ptr", piCost ; INT* in/out
, "UInt") ; return: DWORD●MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost) = DLL("msi.dll", "dword MsiGetFeatureCostA(dword, char*, int, int, void*)")
# 呼び出し: MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost)
# hInstall : MSIHANDLE -> "dword"
# szFeature : LPCSTR -> "char*"
# iCostTree : MSICOSTTREE -> "int"
# iState : INSTALLSTATE -> "int"
# piCost : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "msi" fn MsiGetFeatureCostA(
hInstall: u32, // MSIHANDLE
szFeature: [*c]const u8, // LPCSTR
iCostTree: i32, // MSICOSTTREE
iState: i32, // INSTALLSTATE
piCost: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) u32;proc MsiGetFeatureCostA(
hInstall: uint32, # MSIHANDLE
szFeature: cstring, # LPCSTR
iCostTree: int32, # MSICOSTTREE
iState: int32, # INSTALLSTATE
piCost: ptr int32 # INT* in/out
): uint32 {.importc: "MsiGetFeatureCostA", stdcall, dynlib: "msi.dll".}pragma(lib, "msi");
extern(Windows)
uint MsiGetFeatureCostA(
uint hInstall, // MSIHANDLE
const(char)* szFeature, // LPCSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
int* piCost // INT* in/out
);ccall((:MsiGetFeatureCostA, "msi.dll"), stdcall, UInt32,
(UInt32, Cstring, Int32, Int32, Ptr{Int32}),
hInstall, szFeature, iCostTree, iState, piCost)
# hInstall : MSIHANDLE -> UInt32
# szFeature : LPCSTR -> Cstring
# iCostTree : MSICOSTTREE -> Int32
# iState : INSTALLSTATE -> Int32
# piCost : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t MsiGetFeatureCostA(
uint32_t hInstall,
const char* szFeature,
int32_t iCostTree,
int32_t iState,
int32_t* piCost);
]]
local msi = ffi.load("msi")
-- msi.MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost)
-- hInstall : MSIHANDLE
-- szFeature : LPCSTR
-- iCostTree : MSICOSTTREE
-- iState : INSTALLSTATE
-- piCost : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('msi.dll');
const MsiGetFeatureCostA = lib.func('__stdcall', 'MsiGetFeatureCostA', 'uint32_t', ['uint32_t', 'str', 'int32_t', 'int32_t', 'int32_t *']);
// MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost)
// hInstall : MSIHANDLE -> 'uint32_t'
// szFeature : LPCSTR -> 'str'
// iCostTree : MSICOSTTREE -> 'int32_t'
// iState : INSTALLSTATE -> 'int32_t'
// piCost : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("msi.dll", {
MsiGetFeatureCostA: { parameters: ["u32", "buffer", "i32", "i32", "pointer"], result: "u32" },
});
// lib.symbols.MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost)
// hInstall : MSIHANDLE -> "u32"
// szFeature : LPCSTR -> "buffer"
// iCostTree : MSICOSTTREE -> "i32"
// iState : INSTALLSTATE -> "i32"
// piCost : INT* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t MsiGetFeatureCostA(
uint32_t hInstall,
const char* szFeature,
int32_t iCostTree,
int32_t iState,
int32_t* piCost);
C, "msi.dll");
// $ffi->MsiGetFeatureCostA(hInstall, szFeature, iCostTree, iState, piCost);
// hInstall : MSIHANDLE
// szFeature : LPCSTR
// 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.ASCII_OPTIONS);
int MsiGetFeatureCostA(
int hInstall, // MSIHANDLE
String szFeature, // LPCSTR
int iCostTree, // MSICOSTTREE
int iState, // INSTALLSTATE
IntByReference piCost // INT* in/out
);
}@[Link("msi")]
lib Libmsi
fun MsiGetFeatureCostA = MsiGetFeatureCostA(
hInstall : UInt32, # MSIHANDLE
szFeature : UInt8*, # LPCSTR
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 MsiGetFeatureCostANative = Uint32 Function(Uint32, Pointer<Utf8>, Int32, Int32, Pointer<Int32>);
typedef MsiGetFeatureCostADart = int Function(int, Pointer<Utf8>, int, int, Pointer<Int32>);
final MsiGetFeatureCostA = DynamicLibrary.open('msi.dll')
.lookupFunction<MsiGetFeatureCostANative, MsiGetFeatureCostADart>('MsiGetFeatureCostA');
// hInstall : MSIHANDLE -> Uint32
// szFeature : LPCSTR -> Pointer<Utf8>
// iCostTree : MSICOSTTREE -> Int32
// iState : INSTALLSTATE -> Int32
// piCost : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MsiGetFeatureCostA(
hInstall: DWORD; // MSIHANDLE
szFeature: PAnsiChar; // LPCSTR
iCostTree: Integer; // MSICOSTTREE
iState: Integer; // INSTALLSTATE
piCost: Pointer // INT* in/out
): DWORD; stdcall;
external 'msi.dll' name 'MsiGetFeatureCostA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MsiGetFeatureCostA"
c_MsiGetFeatureCostA :: Word32 -> CString -> Int32 -> Int32 -> Ptr Int32 -> IO Word32
-- hInstall : MSIHANDLE -> Word32
-- szFeature : LPCSTR -> CString
-- iCostTree : MSICOSTTREE -> Int32
-- iState : INSTALLSTATE -> Int32
-- piCost : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let msigetfeaturecosta =
foreign "MsiGetFeatureCostA"
(uint32_t @-> string @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning uint32_t)
(* hInstall : MSIHANDLE -> uint32_t *)
(* szFeature : LPCSTR -> string *)
(* 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 ("MsiGetFeatureCostA" msi-get-feature-cost-a :convention :stdcall) :uint32
(h-install :uint32) ; MSIHANDLE
(sz-feature :string) ; LPCSTR
(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 $MsiGetFeatureCostA = Win32::API::More->new('msi',
'DWORD MsiGetFeatureCostA(DWORD hInstall, LPCSTR szFeature, int iCostTree, int iState, LPVOID piCost)');
# my $ret = $MsiGetFeatureCostA->Call($hInstall, $szFeature, $iCostTree, $iState, $piCost);
# hInstall : MSIHANDLE -> DWORD
# szFeature : LPCSTR -> LPCSTR
# iCostTree : MSICOSTTREE -> int
# iState : INSTALLSTATE -> int
# piCost : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f MsiGetFeatureCostW (Unicode版) — 機能のインストールに必要なディスク容量コストを取得する(Unicode版)。