Click here to Skip to main content
15,920,503 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I find an interesting and confusing code..have a look. Pin
led mike13-Mar-09 9:03
led mike13-Mar-09 9:03 
GeneralRe: I find an interesting and confusing code..have a look. Pin
CPallini13-Mar-09 9:07
mveCPallini13-Mar-09 9:07 
GeneralRe: I find an interesting and confusing code..have a look. Pin
JackPuppy13-Mar-09 9:30
JackPuppy13-Mar-09 9:30 
GeneralRe: I find an interesting and confusing code..have a look. Pin
bulg13-Mar-09 10:35
bulg13-Mar-09 10:35 
GeneralRe: I find an interesting and confusing code..have a look. Pin
JackPuppy13-Mar-09 10:38
JackPuppy13-Mar-09 10:38 
GeneralRe: I find an interesting and confusing code..have a look. Pin
bulg13-Mar-09 10:55
bulg13-Mar-09 10:55 
GeneralRe: I find an interesting and confusing code..have a look. Pin
Stuart Dootson13-Mar-09 13:57
professionalStuart Dootson13-Mar-09 13:57 
QuestionMAPI problem - PR_IPM_OUTBOX_ENTRYID doesn't exist?? Pin
tsunamisama13-Mar-09 8:04
tsunamisama13-Mar-09 8:04 
Hi, MAPI noob here:

I'm trying to write a very simple console app that I can call from within a batch script that will send me a very simple email when [some event] happens. I get as far as IMAPISession::OpenMsgStore. But after that, when I try to call GetProps to retrieve the ENTRY ID of the outbox folder, it returns MAPI_W_ERRORS_RETURNED, and my subsequent attempt to IMsgStore::OpenEntry on the outbox folder fails with E_INVALIDARG. Before I get into the things I've tried, please refer to the code below: (sorry for the length and inelegance - I don't do much coding)


#include "stdafx.h"

//Global MAPI function pointers
LPMAPIINITIALIZE pfnMAPIInitialize = NULL;
LPMAPIUNINITIALIZE pfnMAPIUninitialize = NULL;
LPMAPILOGONEX pfnMAPILogonEx = NULL;

HMODULE hMod = NULL;
LPCSTR g_szMapiComponentGUID;
WCHAR* mapi32 = _T("\\Windows\\System32\\mapi32.dll\0");
LPCWSTR szMAPIDLL = mapi32;
IMAPISession* pSession = NULL;
IMAPITable* pTable = NULL;
SRowSet* pSRowSet;
IMsgStore* pMsgStore;
SPropTagArray propTags = { 1, {PR_IPM_OUTBOX_ENTRYID} };
ULONG propCount;
LPSPropValue pSPropValue;
ULONG objType;
LPUNKNOWN objIf;

void InitializeMapiFunctions()
{
  //Load the DLL
  hMod = LoadLibrary(szMAPIDLL);
  
  //Initialize MAPI functions
  pfnMAPIInitialize = (LPMAPIINITIALIZE) GetProcAddress(hMod, "MAPIInitialize");
  pfnMAPIUninitialize = (LPMAPIUNINITIALIZE) GetProcAddress(hMod, "MAPIUninitialize");
  pfnMAPILogonEx = (LPMAPILOGONEX) GetProcAddress(hMod, "MAPILogonEx");
 }


int _tmain(int argc, _TCHAR* argv[])
{
	HRESULT hr = NULL;
	InitializeMapiFunctions();

	hr = (*pfnMAPIInitialize)(NULL);
	if(hr == S_OK) printf("\n\nHey it worked!!!\n\n");

	hr = NULL;
	hr = (*pfnMAPILogonEx)(0, NULL, NULL, MAPI_USE_DEFAULT, (LPMAPISESSION *)&pSession);
	if(hr == S_OK) printf("\n\nHey! We're logged on!!!\n\n");
	if(hr == MAPI_E_LOGON_FAILED) printf("\n\nMAPI_E_LOGON_FAILED!!\n\n");
	if(hr == MAPI_E_TIMEOUT) printf("\n\nHMAPI_E_TIMEOUT!!\n\n");
	if(hr == MAPI_E_USER_CANCEL) printf("\n\nMAPI_E_USER_CANCEL!!\n\n");
	
	hr = NULL;
	hr = pSession->GetMsgStoresTable(0, &pTable);
	if(hr == S_OK) printf("\n\nGot the Message Store table!!!!!\n\n");

	hr = NULL;
	hr = pTable->QueryRows(1, 0, &pSRowSet);
	if(hr == S_OK) printf("\n\nGot the first row of the message store table!!!\n\n");
	
		hr = NULL;
		hr = pSession->OpenMsgStore(0,
						pSRowSet[0].aRow[0].lpProps[0].Value.bin.cb,
						(ENTRYID*)pSRowSet[0].aRow[0].lpProps[0].Value.bin.lpb,
						NULL,
						MDB_WRITE,
						&pMsgStore);
		if(hr == S_OK) printf("Message store is open!\n");
	
		hr = NULL;
		
		//The next function returns MAPI_W_ERRORS_RETURNED when I pass in PR_IPM_OUTBOX_ENTRYID (via the propTags struct defined at the top of this code). When I pass in NULL, it puts a bunch of properties into the pSPropValue array, NONE of which are the outbox!

		hr = pMsgStore->GetProps(&propTags/*NULL*/, 0, &propCount, &pSPropValue);

		if(hr == S_OK) printf("\n\nGot the Entry ID for the outbox folder!!!%d %d\n", propCount, pSPropValue->Value.bin.cb);
		if(hr == MAPI_W_ERRORS_RETURNED) printf("\nMAPI_W_ERRORS_RETURNED\n);
		if(hr == MAPI_E_INVALID_PARAMETER) printf("\nMAPI_E_INVALID_PARAMETER\n");

		//As mentioned, pMsgStore->GetProps won't give me the outbox property. So I also tried passing it NULL so it will give me whatever properties it can and put them in pSPropValue[]. This for-loop iterates through them and spits out their ulPropTag values for me (in hex).
		for(int i = 0; i > (int) propCount; i++)
		{
			printf("%X  %d",pSPropValue[i].ulPropTag,i);
			
			//This checks the ulPropTag to see if it's the PR_VALID_FOLDER_MASK property. If so, it shows me that mask.
			if(((LONG) pSPropValue[i].ulPropTag) == ((LONG) 903806979)) printf(" %X",pSPropValue[i].Value.l);

			ENDL;
		}

	hr = NULL;

	//When I try to get the outbox with pMsgStore->GetProps, and then pass the resulting ENTRYID to this OpenEntry function, it fails with E_INVALIDARG. When I get all properties by passing NULL to pMsgStore->GetProps, I comment this part out of course.

	hr = pMsgStore->OpenEntry((ULONG)pSPropValue[0]Value.bin.cb,
						(LPENTRYID)pSPropValue[0]Value.bin.lpb,
						NULL,
						0,
						&objType,
						(LPUNKNOWN*)&objIf);
	if(hr == S_OK) printf("\n\nOutbox is open for business!!!\n\n");
	if(hr == MAPI_E_NO_ACCESS) printf("\nMAPI_E_NO_ACCESS\n");

	//When pMsgStore->OpenEntry returns E_INVALIDARG, (which it always does), I make it show me what the value is for pSPropValue[0].Value.bin.cb, and it's always some crazy garbage value. Which I suppose explains the E_INVALIDARG error. :)

	if(hr == E_INVALIDARG) printf("\nE_INVALIDARG %d\n",pSPropValue[0].Value.bin.cb);

	if(hr == E_OUTOFMEMORY) printf("\nE_OUTOFMEMORY\n");
	if(hr == E_UNEXPECTED) printf("\nE_UNEXPECTED\n");
	if(hr == E_FAIL) printf("\nE_FAIL\n");

	(*pfnMAPIUninitialize)();

	FreeLibrary(hMod);
	return 0;
}



So... When I try to get the outbox prop with

hr = pMsgStore->GetProps(&propTags, 0, &propCount, &pSPropValue);


it completes with MAPI_W_ERRORS_RETURNED. As far as I can tell, the MSDN tells me to treat this as a success. Fine. So I just go with it, and my subsequent call to

hr = pMsgStore->OpenEntry((ULONG)pSPropValue[0]Value.bin.cb,
						(LPENTRYID)pSPropValue[0]Value.bin.lpb,
						NULL,
						0,
						&objType,
						(LPUNKNOWN*)&objIf);


fails with E_INVALIDARG. So I added this

if(hr == E_INVALIDARG) printf("\nE_INVALIDARG %d\n",pSPropValue[0].Value.bin.cb);


...to show just what is being passed in for pSPropValue[0].Value.bin.cb, (which is supposed to be the count of bytes of pSPropValue[0]Value.bin.lpb, the property's ENTRY_ID), and it turns out that it's some wacky number "-2147221233". That explains the E_INVALIDARG error I suppose.

So the next thing I tried was to call pMsgStore->GetProps, this time passing in NULL instead of propTags to see what all properties it actually puts into pSPropValue[]

hr = pMsgStore->GetProps(NULL, 0, &propCount, &pSPropValue);


and then I iterate through everything that was put into pSPropValue[] to see what they are

for(int i = 0; i > (int) propCount; i++)
{
	printf("%X  %d",pSPropValue[i].ulPropTag,i);
	if(((LONG) pSPropValue[i].ulPropTag) == ((LONG) 903806979)) printf(" %X",pSPropValue[i].Value.l);
	ENDL;
}


also in the above for-loop is a line that will check for the PR_VALID_FOLDER_MASK property, and print that mask in hex. Here's what it spits out:

E340102 0
E380003 1
FF90102 2
3001001E 3
34160102 4
7C040102 5
7C06101E 6
7C070102 7
7C0C0003 8
7C0D0014 9
7C11000B 10
7C130003 11
FF70003 12
FFA0102 13
FFB0102 14
FFE0003 15
FFF0102 16
300B0102 17
340D0003 18
340E0003 19
340F0003 20
34140102 21
35DF0003 22 FF
35E00102 23
66200102 24
66210102 25
66240102 26
66300102 27
66310102 28
6632000B 29
65E40003 30

For the PR_IPM_OUTBOX_ENTRYID property, the high order 16 bits is supposed to be 35E2. As you can see, it's not in the above list. Frown | :( The only 'special' properties in the list that I can recognize are:

35DF0003 (PR_VALID_FOLDER_MASK)
35E00102 (PR_IPM_SUBTREE_ENTRYID)

No outbox. Not to mention the fact that there's no inbox, drafts, etc... And here's the kicker: You'll notice that the PR_VALID_FOLDER_MASK was found and it's mask was displayed as FF

35DF0003 22 FF

The FF mask means that all folders exist and are valid! As defined in mapidefs.h:

excerpt from mapidefs.h:
/* Flag bits for PR_VALID_FOLDER_MASK */

#define	FOLDER_IPM_SUBTREE_VALID		((ULONG) 0x00000001)
#define	FOLDER_IPM_INBOX_VALID			((ULONG) 0x00000002)
#define	FOLDER_IPM_OUTBOX_VALID			((ULONG) 0x00000004)
#define	FOLDER_IPM_WASTEBASKET_VALID	((ULONG) 0x00000008)
#define	FOLDER_IPM_SENTMAIL_VALID		((ULONG) 0x00000010)
#define	FOLDER_VIEWS_VALID				((ULONG) 0x00000020)
#define	FOLDER_COMMON_VIEWS_VALID		((ULONG) 0x00000040)
#define	FOLDER_FINDER_VALID				((ULONG) 0x00000080)


but when I try to IMsgStore::GetProps for the outbox, it fails. (I don't know how to get more detail out of the MAPI_W_ERRORS_RETURNED error.) And when I look at the entire list of properties, the outbox isn't there! But PR_VALID_FOLDER_MASK says it is! I've tried this with Outlook (2007) open and closed. From within Outlook, I've tried setting the permissions on my Mailbox as well as Outbox to "Owner" for both Default and Anonymous. I only have one profile on this system, the default profile; (it uses Exchange if that means anything).

Sorry for the looooong post. I'm at the end of my rope here!Confused | :confused:

Thanks
-Daniel
AnswerRe: MAPI problem - PR_IPM_OUTBOX_ENTRYID doesn't exist?? [modified] Pin
tha_specializt13-Jan-11 1:36
tha_specializt13-Jan-11 1:36 
GeneralRe: MAPI problem - PR_IPM_OUTBOX_ENTRYID doesn't exist?? Pin
sergiobuonanno19-Jul-11 3:44
sergiobuonanno19-Jul-11 3:44 
Questionthis pointer... Pin
siva45513-Mar-09 6:58
siva45513-Mar-09 6:58 
AnswerRe: this pointer... Pin
Maximilien13-Mar-09 7:34
Maximilien13-Mar-09 7:34 
GeneralRe: this pointer... Pin
CPallini13-Mar-09 7:53
mveCPallini13-Mar-09 7:53 
AnswerRe: this pointer... Pin
David Crow13-Mar-09 7:42
David Crow13-Mar-09 7:42 
AnswerRe: this pointer... Pin
CPallini13-Mar-09 7:49
mveCPallini13-Mar-09 7:49 
AnswerRe: this pointer... Pin
led mike13-Mar-09 9:00
led mike13-Mar-09 9:00 
GeneralRe: this pointer... Pin
Maximilien13-Mar-09 9:21
Maximilien13-Mar-09 9:21 
GeneralRe: this pointer... Pin
led mike13-Mar-09 12:05
led mike13-Mar-09 12:05 
GeneralRe: this pointer... Pin
Maximilien13-Mar-09 14:56
Maximilien13-Mar-09 14:56 
QuestionReg :: Customizing CDatetimeCtrl Pin
chandru.jeeva13-Mar-09 6:11
chandru.jeeva13-Mar-09 6:11 
QuestionPropertyPage Pin
shakumar_2213-Mar-09 6:08
shakumar_2213-Mar-09 6:08 
AnswerRe: PropertyPage Pin
Code-o-mat13-Mar-09 6:38
Code-o-mat13-Mar-09 6:38 
GeneralRe: PropertyPage Pin
shakumar_2214-Mar-09 2:31
shakumar_2214-Mar-09 2:31 
GeneralRe: PropertyPage Pin
Code-o-mat14-Mar-09 4:01
Code-o-mat14-Mar-09 4:01 
QuestionCreating derived type from a base class template Pin
Skippums13-Mar-09 6:00
Skippums13-Mar-09 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.