如何获取默认配置文件.pst文件的路径(PR_PST_PATH属性)

时间:2009-08-16 12:29:49

标签: c++ outlook mapi

我正在尝试为outlook开发自定义地址簿提供程序。 使用MFCMAPI浏览商店,我发现可以通过IProviderAdmin-Interface访问outlook默认配置文件的.pst文件的PR_PST_PATH属性。

所以我尝试了下面的mapi代码:

// Get ProfileAdmin
LPPROFADMIN lpProfileAdmin = NULL;
hRes = MAPIAdminProfiles(0, &lpProfileAdmin);
if (FAILED(hRes) || lpProfileAdmin == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

// Get ProfileTable and filter default profile
LPMAPITABLE lpProfileTable = NULL;
hRes = lpProfileAdmin->GetProfileTable(0, &lpProfileTable);
if (FAILED(hRes) || lpProfileTable == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

SPropValue spvDefaultProfile;
spvDefaultProfile.ulPropTag = PR_DEFAULT_PROFILE;
spvDefaultProfile.Value.b = TRUE;

SRestriction srProfile;
srProfile.rt = RES_PROPERTY;
srProfile.res.resProperty.relop = RELOP_EQ;
srProfile.res.resProperty.ulPropTag = PR_DEFAULT_PROFILE;
srProfile.res.resProperty.lpProp = &spvDefaultProfile;

hRes = lpProfileTable->Restrict(&srProfile, TBL_BATCH);
hRes = lpProfileTable->FindRow(&srProfile, BOOKMARK_BEGINNING, 0);

LPSRowSet lpRowSet = NULL;
hRes = lpProfileTable->QueryRows(1, 0, &lpRowSet);
if (FAILED(hRes) || lpRowSet == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

bstr_t profileName((const char *)lpRowSet->aRow[0].lpProps[0].Value.lpszA);
lpzProfileName = (LPTSTR)profileName;

// Get ServiceAdmin
LPSERVICEADMIN lpServiceAdmin = NULL;
hRes = lpProfileAdmin->AdminServices(lpzProfileName, NULL, NULL, MAPI_UNICODE, &lpServiceAdmin);
if (FAILED(hRes) || lpServiceAdmin == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

// Get ServiceTable and filter default store
LPMAPITABLE lpServiceTable = NULL;
hRes = lpServiceAdmin->GetMsgServiceTable(0, &lpServiceTable);
if (FAILED(hRes) || lpServiceTable == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

SRestriction srService;
srService.rt = RES_BITMASK;
srService.res.resBitMask.ulPropTag = PR_RESOURCE_FLAGS;
srService.res.resBitMask.relBMR = BMR_EQZ;
srService.res.resBitMask.ulMask = SERVICE_DEFAULT_STORE;

hRes = lpServiceTable->Restrict(&srService, TBL_BATCH);
hRes = lpServiceTable->FindRow(&srService, BOOKMARK_BEGINNING, 0);

lpRowSet = NULL;
hRes = lpServiceTable->QueryRows(1, 0, &lpRowSet);
if (FAILED(hRes) || lpRowSet == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

// Get UID Property for default store
LPSPropValue pValServiceUid = PpropFindProp(lpRowSet->aRow[0].lpProps, lpRowSet->aRow[0].cValues, PR_SERVICE_UID);
if (pValServiceUid == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

// Get ProfileSection for UID
LPPROFSECT lpProfileSect = NULL;
hRes = lpServiceAdmin->OpenProfileSection((LPMAPIUID)pValServiceUid->Value.bin.lpb, NULL, MAPI_FORCE_ACCESS, &lpProfileSect);  
if (FAILED(hRes) || lpProfileSect == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

// Get UID of IProviderAdmin
LPSPropValue pValProviderUid = NULL;
hRes = HrGetOneProp(lpProfileSect, PR_STORE_PROVIDERS, &pValProviderUid);
if (FAILED(hRes) || pValProviderUid == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

LPPROVIDERADMIN lpProviderAdmin = NULL;
hRes = lpServiceAdmin->AdminProviders((LPMAPIUID)pValProviderUid->Value.bin.lpb, 0, &lpProviderAdmin);
if (FAILED(hRes) || lpProviderAdmin == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

LPMAPITABLE lpProviderTable = NULL;
hRes = lpProviderAdmin->GetProviderTable(0, &lpProviderTable);
if (FAILED(hRes) || lpProviderTable == NULL) {
    hRes = MAPI_E_UNCONFIGURED;
    return hRes;
}

但是打电话给

lpServiceAdmin->AdminProviders(...)

失败,返回值为E_INVALIDARGS

那么,我做错了什么?获取PR_PST_PATH属性的正确方法是什么?

此致

勒夫

1 个答案:

答案 0 :(得分:0)

确认pValProviderUid与您在MFCMAPI中看到的匹配。