프로그램에서 Database Functions 호출

사용자 지정 작업 또는 자동화 프로세스와 같은 프로그램에서 다음 Database Functions를 호출하기 전에 설치 관리자가 먼저 CostInitialize 작업, FileCost 작업CostFinalize 작업을 실행해야 합니다.

다음은 Windows Installer에서 사용되는 데이터베이스 함수의 목록입니다.

프로그램에서 MsiSetFeatureAttributes를 호출하기 전에 설치 관리자는 먼저 CostInitialize 작업을 실행해야 합니다. 그런 다음, 설치 관리자는 MsiSetFeatureAttributes 다음에 CostFinalize 작업을 실행합니다.

다음 예에서는 프로그램에서 MsiGetTargetPath를 사용할 때 함수 작업을 호출해야 하는 순서를 보여줍니다.

#include <windows.h>
#include <Msiquery.h>
#include <tchar.h>
#pragma comment(lib, "msi.lib") 

int main()  
{ 

MSIHANDLE hInstall;
TCHAR *szBuf;
DWORD cch  = 0 ;
 
if(MsiOpenPackage(_T("PathToPackage...."), &hInstall) == ERROR_SUCCESS)
{
    if(MsiDoAction(hInstall, _T("CostInitialize"))==ERROR_SUCCESS  
        && MsiDoAction(hInstall, _T("FileCost"))==ERROR_SUCCESS  
        && MsiDoAction(hInstall, _T("CostFinalize"))==ERROR_SUCCESS)   
    { 
        if(MsiGetTargetPath(hInstall, _T("FolderName"), _T(""),&cch)==ERROR_MORE_DATA)
        { 
            cch++; // add 1 to include null terminator since MsiGetTargetPath does not include it on return 
            szBuf = (TCHAR *) malloc(cch*sizeof(TCHAR));
            if(szBuf)
            {
                if(MsiGetTargetPath(hInstall, _T("FolderName"), szBuf,&cch)==ERROR_SUCCESS)
                {
                    // Add code to use szBuf here
                }
                free(szBuf);
            }
        } 
    } 
    MsiCloseHandle(hInstall);
}

return 0;  
}