Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Installer
Installer Database
Database Functions
 MsiGetProperty Function
MsiGetProperty Function

The MsiGetProperty function gets the value for an installer property.

Syntax

UINT MsiGetProperty(
  __in     MSIHANDLE hInstall,
  __in     LPCTSTR szName,
  __out    LPTSTR szValueBuf,
  __inout  DWORD *pchValueBuf
);

Parameters

hInstall [in]

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

szName [in]

A null-terminated string that specifies the name of the property.

szValueBuf [out]

Pointer to the buffer that receives the null terminated string containing the value of the property. Do not attempt to determine the size of the buffer by passing in a null (value=0) for szValueBuf. You can get the size of the buffer by passing in an empty string (for example ""). The function will then return ERROR_MORE_DATA and pchValueBuf will contain the required buffer size in TCHARs, not including the terminating null character. On return of ERROR_SUCCESS, pcchValueBuf contains the number of TCHARs written to the buffer, not including the terminating null character.

pchValueBuf [in, out]

Pointer to the variable that specifies the size, in TCHARs, of the buffer pointed to by the variable szValueBuf. When the function returns ERROR_SUCCESS, this variable contains the size of the data copied to szValueBuf, not including the terminating null character. If szValueBuf is not not large enough, the function returns ERROR_MORE_DATA and stores the required size, not including the terminating null character, in the variable pointed to by pchValueBuf.

Return Value

ERROR_INVALID_HANDLE

An invalid or inactive handle was supplied.

ERROR_INVALID_PARAMETER

An invalid parameter was passed to the function.

ERROR_MORE_DATA

The provided buffer was too small to hold the entire value.

ERROR_SUCCESS

The function succeeded.

Remarks

If the value for the property retrieved by the MsiGetProperty function is not defined, it is equivalent to a 0-length value. It is not an error.

If ERROR_MORE_DATA is returned, the parameter which is a pointer gives the size of the buffer required to hold the string. If ERROR_SUCCESS is returned, it gives the number of characters written to the string buffer. Therefore you can get the size of the buffer by passing in an empty string (for example "") for the parameter that specifies the buffer. Do not attempt to determine the size of the buffer by passing in a Null (value=0).

The following example shows how a DLL custom action could access the value of a property by dynamically determining the size of the value buffer.

    
UINT __stdcall MyCustomAction(MSIHANDLE hInstall)
{
    TCHAR* szValueBuf = NULL;
    DWORD cchValueBuf = 0;
    UINT uiStat =  MsiGetProperty(hInstall, TEXT("MyProperty"), TEXT(""), &cchValueBuf);
    if (ERROR_MORE_DATA == uiStat)
    {
        ++cchValueBuf; // on output does not include terminating null, so add 1
        szValueBuf = new TCHAR[cchValueBuf];
        if (szValueBuf)
        {
            uiStat = MsiGetProperty(hInstall, TEXT("MyProperty"), szValueBuf, &cchValueBuf);
        }
    }
    if (ERROR_SUCCESS != uiStat)
    {
        if (szValueBuf != NULL) 
	delete [] szValueBuf;
	return ERROR_INSTALL_FAILURE;
    }

    // custom action uses MyProperty
    // ...

    delete [] szValueBuf;

    return ERROR_SUCCESS;
}
        

Requirements

Version Requires Windows Installer 4.0 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003, Windows XP, and Windows 2000.
Header

Declared in Msiquery.h.

Library

Use Msi.lib.

DLL

Requires Msi.dll.

Unicode/ANSI

Implemented as MsiGetPropertyW (Unicode) and MsiGetPropertyA (ANSI).

See Also

Installer State Access Functions
Passing Null as the Argument of Windows Installer Functions


Send comments about this topic to Microsoft

Build date: 6/5/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Beware the buffer size gotcha!      Wiggers   |   Edit   |  
Note that if you make multiple calls to MsiGetProperty the value in pchValueBuf gets changed each time. And even if you are expecting the same length string each time, the value gets set to one less than the actual buffer size! Very shoddy design... IMHO.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker