Nauman Hameed
Guest
|
Posted:
Tue Jan 11, 2005 7:23 pm Post subject:
Error while getting pointer of a sub folder |
|
|
Hi
I am trying to open the Inbox folder of an Exchange Server mailbox. I
follow these steps to do this.
1. Initialize MAPI (MAPIInitialize)
2. Create a session using an explicit profile (MAPILogonEx)
3. Get the message stores table (session->GetMsgStoresTable)
4. Open the required message store after getting the entry ID from the
table obtained in step 4 (session->OpenMsgStore)
5. Get the root folder entry ID from the message store (msgStore->GetProps
to get PR_IPM_SUBTREE_ENTRYID property)
6. Open the root folder using the entry ID obtained in step 5.
(msgStore->OpenEntry)
7. Get the hierarchy table for the root folder
(rootFolder->GetHierarchyTable)
8. Get the entry ID of a sub folder, e.g. Inbox, from the hierarchy table (
the PR_LONGTERM_ENTRYID_FROM_TABLE property )
9. Open the sub folder using the entry ID obtained in step 8
(rootFolder->OpenEntry)
The code works fine upto step 9. The code for step 9 returns successfully (
hr == S_OK ). However, when I try to use the pointer of sub folder for any
operations on the sub folder, I get an exception with the message "Object
reference not set to an instance of an object."
I have used the GetReceiveFolder method as well (msgStore-
| Quote: | GetReceiveFolder). The results are same. The entry ID that I get in step 8
and the entry ID that I get using the GetReceiveFolder are same. |
I have verified the entry ID that I get in my code using OutlookSpy.
OutlookSpy reports the same entry ID for the Inbox folder. If I use the
OpenEntry dialog provided by OutlookSpy, it successfully opens the Inbox
folder using the same entry ID.
I use following lines of code to open the sub folder (Inbox folder).
/---------------------------\
SBinary subFolderEID;
LPMAPIFOLDER subFolder = NULL;
ULONG lpulObjType;
LPUNKNOWN lppUnk = NULL;
hr = rootFolder->OpenEntry(subFolderEID.cb, (LPENTRYID) subFolderEID.lpb,
&IID_IMAPIFolder, MAPI_MODIFY, &lpulObjType, &lppUnk);
subFolder = (LPMAPIFOLDER) &lppUnk;
\----------------------------/
In the OpenEntry call I have tried different combinations of flags other
than MAPI_MODIFY but no use.
Can anyone provide some insight?
Thanks
Nauman
|
|
Nauman Hameed
Guest
|
Posted:
Wed Jan 12, 2005 6:59 pm Post subject:
RE: Error while getting pointer of a sub folder |
|
|
Found the solution from another forum. The last line of the code pasted below
is:
subFolder = (LPMAPIFOLDER) &lppUnk;
The & with lppUnk is the culprit. It should be:
subFolder = (LPMAPIFOLDER) lppUnk; // Without the &
Nauman
"Nauman Hameed" wrote:
| Quote: | Hi
I am trying to open the Inbox folder of an Exchange Server mailbox. I
follow these steps to do this.
1. Initialize MAPI (MAPIInitialize)
2. Create a session using an explicit profile (MAPILogonEx)
3. Get the message stores table (session->GetMsgStoresTable)
4. Open the required message store after getting the entry ID from the
table obtained in step 4 (session->OpenMsgStore)
5. Get the root folder entry ID from the message store (msgStore->GetProps
to get PR_IPM_SUBTREE_ENTRYID property)
6. Open the root folder using the entry ID obtained in step 5.
(msgStore->OpenEntry)
7. Get the hierarchy table for the root folder
(rootFolder->GetHierarchyTable)
8. Get the entry ID of a sub folder, e.g. Inbox, from the hierarchy table (
the PR_LONGTERM_ENTRYID_FROM_TABLE property )
9. Open the sub folder using the entry ID obtained in step 8
(rootFolder->OpenEntry)
The code works fine upto step 9. The code for step 9 returns successfully (
hr == S_OK ). However, when I try to use the pointer of sub folder for any
operations on the sub folder, I get an exception with the message "Object
reference not set to an instance of an object."
I have used the GetReceiveFolder method as well (msgStore-
GetReceiveFolder). The results are same. The entry ID that I get in step 8
and the entry ID that I get using the GetReceiveFolder are same.
I have verified the entry ID that I get in my code using OutlookSpy.
OutlookSpy reports the same entry ID for the Inbox folder. If I use the
OpenEntry dialog provided by OutlookSpy, it successfully opens the Inbox
folder using the same entry ID.
I use following lines of code to open the sub folder (Inbox folder).
/---------------------------\
SBinary subFolderEID;
LPMAPIFOLDER subFolder = NULL;
ULONG lpulObjType;
LPUNKNOWN lppUnk = NULL;
hr = rootFolder->OpenEntry(subFolderEID.cb, (LPENTRYID) subFolderEID.lpb,
&IID_IMAPIFolder, MAPI_MODIFY, &lpulObjType, &lppUnk);
subFolder = (LPMAPIFOLDER) &lppUnk;
\----------------------------/
In the OpenEntry call I have tried different combinations of flags other
than MAPI_MODIFY but no use.
Can anyone provide some insight?
Thanks
Nauman
|
|
|