MsiGetFeatureCost function

The MsiGetFeatureCost function returns the disk space required by a feature and its selected children and parent features.

Syntax


UINT MsiGetFeatureCost(
  _In_  MSIHANDLE    hInstall,
  _In_  LPCTSTR      szFeature,
  _In_  MSICOSTTREE  iCostTree,
  _In_  INSTALLSTATE iState,
  _Out_ INT          *piCost
);

Parameters

hInstall [in]

Handle to the installation provided to a DLL custom action or obtained through MsiOpenPackage, MsiOpenPackageEx, or MsiOpenProduct.

szFeature [in]

Specifies the name of the feature.

iCostTree [in]

Specifies the value the function uses to determine disk space requirements. This parameter can be one of the following values.

ValueMeaning
MSICOSTTREE_CHILDREN

The children of the indicated feature are included in the cost.

MSICOSTTREE_PARENTS

The parent features of the indicated feature are included in the cost.

MSICOSTTREE_SELFONLY

The feature only is included in the cost.

 

iState [in]

Specifies the installation state. This parameter can be one of the following values.

ValueMeaning
INSTALLSTATE_UNKNOWN

The product or feature is unrecognized.

INSTALLSTATE_ABSENT

The product or feature is uninstalled.

INSTALLSTATE_LOCAL

The product or feature is installed on the local drive.

INSTALLSTATE_SOURCE

The product or feature is installed to run from source, CD, or network.

INSTALLSTATE_DEFAULT

The product or feature will be installed to use the default location: local or source.

 

piCost [out]

Receives the disk space requirements in units of 512 bytes. This parameter must not be null.

Return value

The MsiGetFeatureCost function returns the following values:

ERROR_FUNCTION_FAILED

The function failed.

ERROR_INVALID_HANDLE

An invalid or inactive handle was supplied.

ERROR_INVALID_HANDLE_STATE

An invalid handle state was supplied.

ERROR_INVALID_PARAMETER

An invalid parameter was passed to the function.

ERROR_SUCCESS

The function succeeded.

ERROR_UNKNOWN_FEATURE

An unknown feature was requested.

Remarks

See Calling Database Functions From Programs.

With the MsiGetFeatureCost function, the MSICOSTTREE_SELFONLY value indicates the total amount of disk space (in units of 512 bytes) required by the specified feature only. This returned value does not include the children or the parent features of the specified feature. This total cost is made up of the disk costs attributed to every component linked to the feature.

The MSICOSTTREE_CHILDREN value indicates the total amount of disk space (in units of 512 bytes) required by the specified feature and its children. For each feature, the total cost is made up of the disk costs attributed to every component linked to the feature.

The MSICOSTTREE_PARENTS value indicates the total amount of disk space (in units of 512 bytes) required by the specified feature and its parent features (up to the root of the Feature table). For each feature, the total cost is made up of the disk costs attributed to every component linked to the feature.

MsiGetFeatureCost is dependent upon several other functions to be successful. The following example demonstrates the order in which these functions must be called:

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

The process to query the cost of features scheduled to be removed is slightly different:

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

If the function fails, you can obtain extended error information by using MsiGetLastErrorRecord.

Requirements

Version

Windows Installer 5.0 on Windows Server 2012, Windows 8, Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003 or Windows XP

Header

Msiquery.h

Library

Msi.lib

DLL

Msi.dll

Unicode and ANSI names

MsiGetFeatureCostW (Unicode) and MsiGetFeatureCostA (ANSI)

See also

Installer Selection Functions
Passing Null as the Argument of Windows Installer Functions

 

 

Show: