Win32 API 日本語リファレンス
ホームSystem.ApplicationInstallationAndServicing › MsiGetFeatureCostW

MsiGetFeatureCostW

関数
機能のインストールに必要なディスク容量コストを取得する(Unicode版)。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiGetFeatureCostW(
    MSIHANDLE hInstall,
    LPCWSTR szFeature,
    MSICOSTTREE iCostTree,
    INSTALLSTATE iState,
    INT* piCost
);

パラメーター

名前方向
hInstallMSIHANDLEin
szFeatureLPCWSTRin
iCostTreeMSICOSTTREEin
iStateINSTALLSTATEin
piCostINT*inout

戻り値の型: DWORD

各言語での呼び出し定義

// 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // DWORD
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';
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 版の利用を推奨。