1

我对此完全不了解,所以需要一些帮助。我正在尝试使用MsiGetSummaryInformationMsiSummaryInfoGetProperty

我不是来自 C++ 背景,所以你必须忍受我。这是我的尝试:

    UINT sisStatus = MsiGetSummaryInformation(0,originalTransform,0,&sumh);
    //UINT sisStatus = MsiGetSummaryInformation(hDbObject,0,0,&sumh);
    if (ERROR_SUCCESS == sisStatus)
    {
        //success - start getting/setting SIS
        //UINT property_type = VT_LPSTR;

        UINT pcount;
        MsiSummaryInfoGetPropertyCount(sumh,&pcount);
        wcout << "PCount " << pcount << endl;

        UINT getpropertyid = 2; 
        UINT returnpropertyid;      
        int returnedIntPropData;
        FILETIME fileValPtr;     
        LPDWORD stringDataLength = 0;           
        LPWSTR propdata = L"";

        MsiSummaryInfoGetProperty(sumh,getpropertyid,&returnpropertyid,&returnedIntPropData,&fileValPtr,propdata, stringDataLength);

        wcout << "Propdata " << propdata << endl;
        wcout << "Stringlength " << stringDataLength << endl;


    }

但它似乎不起作用。返回的值似乎不正确。任何人都可以解释一下吗?

更新

这是我的新(更新)示例:

UINT getpropertyid = 2; 
        UINT returnpropertyid;      
        int returnedIntPropData;
        FILETIME fileValPtr;     
        LPDWORD stringDataLength = new DWORD();     
        LPWSTR propdata = new TCHAR[];

        UINT gps = MsiSummaryInfoGetProperty(sumh,getpropertyid,&returnpropertyid,&returnedIntPropData,&fileValPtr,propdata, stringDataLength);
        if (ERROR_SUCCESS == gps)
        {
            wcout << "RETURN CODE: " << gps << endl;

        wcout << "Propdata " << propdata << endl;
        wcout << "Stringlength " << stringDataLength << endl;
         }
        else
        {
            wcout << "RETURN CODE EXPAND: " << gps << endl;             

            int num = (int)stringDataLength;
            wcout << "Buffer size: " << num << endl;

            propdata = new TCHAR[num];
            stringDataLength = new DWORD(num);  

            MsiSummaryInfoGetProperty(sumh,getpropertyid,&returnpropertyid,&returnedIntPropData,&fileValPtr,propdata, stringDataLength);

            wcout << "Propdata " << propdata << endl;
            wcout << "Stringlength " << stringDataLength << endl;   


        }

这一行: wcout << "缓冲区大小:" << num << endl;

返回 3873856,看起来有点大?我觉得我的编码有点乱。你的例子将是一个很大的帮助!

4

1 回答 1

0

避免调用 new;如果你真的不知道自己在做什么,那会让你进入一个痛苦的世界。而是传递您已经分配的存储地址(例如,通过声明一个本地整数值,或在 std::wstring 的缓冲区中)。我已经修改了您的第一个示例,使其更加符合我的编写方式,尽管我很少最终会在一个地方使用 wcout。(请注意,仍然有一个悬空变量 fororiginalTransform和一个硬编码的uiProperty。)

PMSIHANDLE hSum;
DWORD dwErr = MsiGetSummaryInformation(0, originalTransform, 0, &hSum);
if (ERROR_SUCCESS == dwErr)
{
    UINT uiProperty = 2;
    UINT uiDataType = 0;
    INT iValue = 0;
    FILETIME ftValue = {0};
    std::wstring sValue;
    DWORD cchValue = MAX_PATH;
    sValue.resize(cchValue);
    dwErr = MsiSummaryInfoGetProperty(hSum, uiProperty, &uiDataType, &iValue, &ftValue, const_cast<LPWSTR>(sValue.data()), &cchValue);
    if (ERROR_MORE_DATA == dwErr)
    {
        sValue.resize(++cchValue);
        dwErr = MsiSummaryInfoGetProperty(hSum, uiProperty, &uiDataType, &iValue, &ftValue, const_cast<LPWSTR>(sValue.data()), &cchValue);
    }
    if (ERROR_SUCCESS == dwErr)
    {
        sValue.resize(cchBuf);
        if (VT_LPSTR == uiDataType)
            wcout << "String Data (" << cchBuf << "): " << sValue << "\n";
        else if (VT_I4 == uiDataType)
            wcout << "Numeric Data: " << iValue << "\n";
    }
    else
    {
        wcout << "Error retrieving property: " << dwErr << "\n";
    }
}
else
{
    wcout << "Error retrieving summary info: " << dwErr << "\n";
}
于 2013-10-25T12:32:18.567 回答