0

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

所以我尝试了以下一段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财产的正确方法是什么?

问候

约阿希姆

4

1 回答 1

0

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

于 2009-12-21T02:06:41.210 回答