|
|
|
date: Fri, 14 Mar 2008 02:34:00 -0700,
group: microsoft.public.platformsdk.mapi
back
IMAPISession::SetDefaultStore
Hi,
I´m trying to setup a profil for Outlook with MAPI.
So far so good. It´s no problem to create the profil an editing this.
But i want to use a pst-file as default store and always get an error.
"This informationstorage can´t used as standardstore"
But in the account-settings I can chose the pst-file.
I´m using the following function:
Any suggestions???
HRESULT SetDefStore(char* ProfileName) {
LPMAPISESSION lpMAPISession = NULL;
LPMAPITABLE pStoresTbl = NULL;
LPSRowSet pRows = NULL;
static SRestriction sres;
HRESULT hRes;
LPMDB lpTempMDB = NULL;
enum {EID, NAME, DEFSTORE, NUM_COLS};
LPSRow prow = NULL;
static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, PR_ENTRYID,
PR_DISPLAY_NAME, PR_DEFAULT_STORE};
hRes = MAPIInitialize(NULL);
if (HR_FAILED(hRes)) {
printf("MAPIInitialize failed: %X\n",hRes);
return hRes;
}
hRes = MAPILogonEx(0, ProfileName, NULL, MAPI_NO_MAIL | MAPI_NEW_SESSION |
MAPI_EXTENDED, &lpMAPISession);
hRes = lpMAPISession->lpVtbl->GetMsgStoresTable(lpMAPISession, 0,
&pStoresTbl);
if (HR_FAILED(hRes)) {
printf("GetMsgStoresTable failed: %X\n",hRes);
goto quit;
}
hRes = HrQueryAllRows(
pStoresTbl, //Table to query
(LPSPropTagArray) &sptCols, //Which columns to get
NULL, //No Restriction
NULL, //No sort order
0, //Max number of rows (0 means no limit)
&pRows); //Array to return
if (HR_FAILED(hRes)) {
printf("HrQueryAllRows failed: %X\n",hRes);
goto quit;
}
for(prow = pRows->aRow; prow < pRows->aRow + cProviders; ++prow) {
Assert(prow->cValues == cptaSvc);
Assert(prow->lpProps[EID].Value.bin.lpb == PR_ENTRYID);
Assert(prow->lpProps[NAME].ulPropTag == PR_DISPLAY_NAME);
Assert(prow->lpProps[DEFSTORE].ulPropTag == PR_DEFAULT_STORE);
if(prow->lpProps[DEFSTORE].Value.b == FALSE) {
hRes = lpMAPISession->lpVtbl->SetDefaultStore(lpMAPISession,
MAPI_DEFAULT_STORE, //Establishes the message store as the session
default. Updates the message store's status table row by setting the
STATUS_DEFAULT_STORE flag in the PR_RESOURCE_FLAGS column.
prow->lpProps[EID].Value.bin.cb,
(LPENTRYID)prow->lpProps[EID].Value.bin.lpb);
if (HR_FAILED(hRes)) {
printf("SetDefaultStore failed: %X\n",hRes);
goto quit;
}
}
}
quit:
FreeProws(pRows);
UlRelease(pStoresTbl);
if (FAILED(hRes)){
HRESULT hr;
LPMAPIERROR lpError;
hr = lpMAPISession->lpVtbl->GetLastError(lpMAPISession, hRes,0,&lpError);
if (!hr){
printf("%s\n%s\n",lpError->lpszError,lpError->lpszComponent);
MAPIFreeBuffer(lpError);
}
}
MAPIUninitialize();
return hRes;
}
date: Fri, 14 Mar 2008 02:34:00 -0700
author: MR
Re: IMAPISession::SetDefaultStore
Is that the actual error returned by SetDefaultStore?
Have you tried to use HrValidateIPMSubtree first?
Why do you need to log to that profile? If you create a profile with a
single store, Outlook will automatically make that the default store and
create teh default folders when it first uses the profile.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"MR" wrote in message
news:9F24FA0E-EC7D-4948-917F-1AEC86F55C52@microsoft.com...
> Hi,
>
> I´m trying to setup a profil for Outlook with MAPI.
> So far so good. It´s no problem to create the profil an editing this.
> But i want to use a pst-file as default store and always get an error.
>
> "This informationstorage can´t used as standardstore"
>
> But in the account-settings I can chose the pst-file.
>
> I´m using the following function:
>
> Any suggestions???
>
> HRESULT SetDefStore(char* ProfileName) {
> LPMAPISESSION lpMAPISession = NULL;
> LPMAPITABLE pStoresTbl = NULL;
> LPSRowSet pRows = NULL;
> static SRestriction sres;
> HRESULT hRes;
> LPMDB lpTempMDB = NULL;
> enum {EID, NAME, DEFSTORE, NUM_COLS};
> LPSRow prow = NULL;
>
> static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, PR_ENTRYID,
> PR_DISPLAY_NAME, PR_DEFAULT_STORE};
>
> hRes = MAPIInitialize(NULL);
> if (HR_FAILED(hRes)) {
> printf("MAPIInitialize failed: %X\n",hRes);
> return hRes;
> }
>
> hRes = MAPILogonEx(0, ProfileName, NULL, MAPI_NO_MAIL | MAPI_NEW_SESSION |
> MAPI_EXTENDED, &lpMAPISession);
>
> hRes = lpMAPISession->lpVtbl->GetMsgStoresTable(lpMAPISession, 0,
> &pStoresTbl);
> if (HR_FAILED(hRes)) {
> printf("GetMsgStoresTable failed: %X\n",hRes);
> goto quit;
> }
>
> hRes = HrQueryAllRows(
> pStoresTbl, //Table to query
> (LPSPropTagArray) &sptCols, //Which columns to get
> NULL, //No Restriction
> NULL, //No sort order
> 0, //Max number of rows (0 means no limit)
> &pRows); //Array to return
>
> if (HR_FAILED(hRes)) {
> printf("HrQueryAllRows failed: %X\n",hRes);
> goto quit;
> }
>
> for(prow = pRows->aRow; prow < pRows->aRow + cProviders; ++prow) {
> Assert(prow->cValues == cptaSvc);
> Assert(prow->lpProps[EID].Value.bin.lpb == PR_ENTRYID);
> Assert(prow->lpProps[NAME].ulPropTag == PR_DISPLAY_NAME);
> Assert(prow->lpProps[DEFSTORE].ulPropTag == PR_DEFAULT_STORE);
> if(prow->lpProps[DEFSTORE].Value.b == FALSE) {
> hRes = lpMAPISession->lpVtbl->SetDefaultStore(lpMAPISession,
> MAPI_DEFAULT_STORE, //Establishes the message store as the session
> default. Updates the message store's status table row by setting the
> STATUS_DEFAULT_STORE flag in the PR_RESOURCE_FLAGS column.
> prow->lpProps[EID].Value.bin.cb,
> (LPENTRYID)prow->lpProps[EID].Value.bin.lpb);
> if (HR_FAILED(hRes)) {
> printf("SetDefaultStore failed: %X\n",hRes);
> goto quit;
> }
> }
> }
> quit:
>
> FreeProws(pRows);
> UlRelease(pStoresTbl);
> if (FAILED(hRes)){
> HRESULT hr;
> LPMAPIERROR lpError;
> hr = lpMAPISession->lpVtbl->GetLastError(lpMAPISession, hRes,0,&lpError);
> if (!hr){
> printf("%s\n%s\n",lpError->lpszError,lpError->lpszComponent);
> MAPIFreeBuffer(lpError);
> }
> }
> MAPIUninitialize();
> return hRes;
> }
>
date: Sun, 16 Mar 2008 00:48:13 -0700
author: Dmitry Streblechenko
Re: IMAPISession::SetDefaultStore
Now if´ve extended my sourcecode with HrVaildateIPMSubtree, but get the same
error.
HRESULT SetDefStore(char* ProfileName) {
LPMAPISESSION lpMAPISession = NULL;
LPMAPITABLE pStoresTbl = NULL;
LPSRowSet pRows = NULL;
static SRestriction sres;
HRESULT hRes;
LPMDB lpTempMDB = NULL;
enum {EID, NAME, DEFSTORE, NUM_COLS};
LPSRow prow = NULL;
static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, PR_ENTRYID,
PR_DISPLAY_NAME, PR_DEFAULT_STORE};
hRes = MAPIInitialize(NULL);
if (HR_FAILED(hRes)) {
printf("MAPIInitialize failed: %X\n",hRes);
return hRes;
}
hRes = MAPILogonEx(0, ProfileName, NULL, MAPI_NO_MAIL | MAPI_EXTENDED |
MAPI_NEW_SESSION, &lpMAPISession);
hRes = lpMAPISession->lpVtbl->GetMsgStoresTable(lpMAPISession, 0,
&pStoresTbl);
if (HR_FAILED(hRes)) {
printf("GetMsgStoresTable failed: %X\n",hRes);
goto quit;
}
hRes = HrQueryAllRows(
pStoresTbl, //Table to query
(LPSPropTagArray) &sptCols, //Which columns to get
NULL, //No Restriction
NULL, //No sort order
0, //Max number of rows (0 means no limit)
&pRows); //Array to return
if (HR_FAILED(hRes)) {
printf("HrQueryAllRows failed: %X\n",hRes);
goto quit;
}
for(prow = pRows->aRow; prow < pRows->aRow + cProviders; ++prow) {
Assert(prow->cValues == cptaSvc);
Assert(prow->lpProps[EID].Value.bin.lpb == PR_ENTRYID);
Assert(prow->lpProps[NAME].ulPropTag == PR_DISPLAY_NAME);
Assert(prow->lpProps[DEFSTORE].ulPropTag == PR_DEFAULT_STORE);
if(prow->lpProps[DEFSTORE].Value.b == FALSE) {
LPMDB FAR * lppMDB;
hRes = lpMAPISession->lpVtbl->OpenMsgStore(lpMAPISession, 0,
prow->lpProps[EID].Value.bin.cb, (LPENTRYID)prow->lpProps[EID].Value.bin.lpb,
NULL, MAPI_BEST_ACCESS, lppMDB);
hRes = HrValidateIPMSubtree( *lppMDB, MAPI_FULL_IPM_TREE |
MAPI_FORCE_CREATE, 0, NULL, NULL);
hRes = lpMAPISession->lpVtbl->SetDefaultStore(lpMAPISession,
MAPI_DEFAULT_STORE, //Establishes the message store as the session
default. Updates the message store's status table row by setting the
STATUS_DEFAULT_STORE flag in the PR_RESOURCE_FLAGS column.
prow->lpProps[EID].Value.bin.cb,
(LPENTRYID)prow->lpProps[EID].Value.bin.lpb);
if (HR_FAILED(hRes)) {
printf("SetDefaultStore failed: %X\n",hRes);
goto quit;
}
}
}
quit:
FreeProws(pRows);
UlRelease(pStoresTbl);
if (FAILED(hRes)){
HRESULT hr;
LPMAPIERROR lpError;
hr = lpMAPISession->lpVtbl->GetLastError(lpMAPISession, hRes,0,&lpError);
if (!hr){
printf("%s\n%s\n",lpError->lpszError,lpError->lpszComponent);
MAPIFreeBuffer(lpError);
}
}
MAPIUninitialize();
return hRes;
}
date: Mon, 17 Mar 2008 03:55:01 -0700
author: MR
Re: IMAPISession::SetDefaultStore
How do you know that the store you are making the default one is the one you
just added?
What othe rstores doi you have in that profile? Is there a chance you are
dealing with a store that cannot be made default (such sa the PF store)?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"MR" wrote in message
news:B49B7811-B731-4314-8157-036C706616BA@microsoft.com...
> Now if´ve extended my sourcecode with HrVaildateIPMSubtree, but get the
> same
> error.
>
> HRESULT SetDefStore(char* ProfileName) {
> LPMAPISESSION lpMAPISession = NULL;
> LPMAPITABLE pStoresTbl = NULL;
> LPSRowSet pRows = NULL;
> static SRestriction sres;
> HRESULT hRes;
> LPMDB lpTempMDB = NULL;
> enum {EID, NAME, DEFSTORE, NUM_COLS};
> LPSRow prow = NULL;
>
> static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, PR_ENTRYID,
> PR_DISPLAY_NAME, PR_DEFAULT_STORE};
>
> hRes = MAPIInitialize(NULL);
> if (HR_FAILED(hRes)) {
> printf("MAPIInitialize failed: %X\n",hRes);
> return hRes;
> }
>
> hRes = MAPILogonEx(0, ProfileName, NULL, MAPI_NO_MAIL | MAPI_EXTENDED |
> MAPI_NEW_SESSION, &lpMAPISession);
>
> hRes = lpMAPISession->lpVtbl->GetMsgStoresTable(lpMAPISession, 0,
> &pStoresTbl);
> if (HR_FAILED(hRes)) {
> printf("GetMsgStoresTable failed: %X\n",hRes);
> goto quit;
> }
>
> hRes = HrQueryAllRows(
> pStoresTbl, //Table to query
> (LPSPropTagArray) &sptCols, //Which columns to get
> NULL, //No Restriction
> NULL, //No sort order
> 0, //Max number of rows (0 means no limit)
> &pRows); //Array to return
>
> if (HR_FAILED(hRes)) {
> printf("HrQueryAllRows failed: %X\n",hRes);
> goto quit;
> }
>
> for(prow = pRows->aRow; prow < pRows->aRow + cProviders; ++prow) {
> Assert(prow->cValues == cptaSvc);
> Assert(prow->lpProps[EID].Value.bin.lpb == PR_ENTRYID);
> Assert(prow->lpProps[NAME].ulPropTag == PR_DISPLAY_NAME);
> Assert(prow->lpProps[DEFSTORE].ulPropTag == PR_DEFAULT_STORE);
> if(prow->lpProps[DEFSTORE].Value.b == FALSE) {
> LPMDB FAR * lppMDB;
>
> hRes = lpMAPISession->lpVtbl->OpenMsgStore(lpMAPISession, 0,
> prow->lpProps[EID].Value.bin.cb,
> (LPENTRYID)prow->lpProps[EID].Value.bin.lpb,
> NULL, MAPI_BEST_ACCESS, lppMDB);
> hRes = HrValidateIPMSubtree( *lppMDB, MAPI_FULL_IPM_TREE |
> MAPI_FORCE_CREATE, 0, NULL, NULL);
>
> hRes = lpMAPISession->lpVtbl->SetDefaultStore(lpMAPISession,
> MAPI_DEFAULT_STORE, //Establishes the message store as the session
> default. Updates the message store's status table row by setting the
> STATUS_DEFAULT_STORE flag in the PR_RESOURCE_FLAGS column.
> prow->lpProps[EID].Value.bin.cb,
> (LPENTRYID)prow->lpProps[EID].Value.bin.lpb);
>
> if (HR_FAILED(hRes)) {
> printf("SetDefaultStore failed: %X\n",hRes);
> goto quit;
> }
> }
> }
> quit:
>
> FreeProws(pRows);
> UlRelease(pStoresTbl);
> if (FAILED(hRes)){
> HRESULT hr;
> LPMAPIERROR lpError;
> hr = lpMAPISession->lpVtbl->GetLastError(lpMAPISession, hRes,0,&lpError);
> if (!hr){
> printf("%s\n%s\n",lpError->lpszError,lpError->lpszComponent);
> MAPIFreeBuffer(lpError);
> }
> }
> MAPIUninitialize();
> return hRes;
> }
date: Mon, 17 Mar 2008 10:04:03 -0700
author: Dmitry Streblechenko
|
|