PC Review


Reply
Thread Tools Rate Thread

Message "The object could not be found"

 
 
=?Utf-8?B?R29waQ==?=
Guest
Posts: n/a
 
      24th May 2005
When I call the method IMAPISession::ShowForm(), I am getting the message
"The object could not be found"

My program, which calls IMAPISession::ShowForm() is working fine on a system
having Outlook 2000 SP-3(9.0.0.6627) on Windows 2000. But the same program
when run on a system having Outlook XP SP3 or Outlook 2003 is giving the
message "The object could not be found", whenever it encounters the call to
IMAPISession::ShowForm(). Pl see the source code below. I am referring to the
line SpSess->ShowForm(...)

-------------------------source code---------------
#include "afxwin.h"
#include <edkafx.h>
#include "safepnt.h"

#include <stdio.h>

void MyItemDoMail( int Item, SpIMAPISession & SpSess, BOOL MailToXYZ = FALSE
);

void Fn()
{
SpIMAPISession SpSess;

printf("before calling MAPIInitialize \n");
::MAPIInitialize( 0 );
printf("after calling MAPIInitialize \n");

HWND m_hWnd = NULL;
if( FAILED( ::MAPILogonEx( (LPARAM)m_hWnd, NULL, NULL, MAPI_LOGON_UI |
MAPI_NO_MAIL, &SpSess ) ))
{
printf("MAPILogonEx failed \n");
::AfxMessageBox( "okok", MB_OK );
return;
}

MyItemDoMail(1, SpSess);

printf("after calling MAPILogonEx \n");


SpSess.Release();
printf("after calling Release \n");

::MAPIUninitialize();
printf("after calling MAPIUninitialize \n");

}


int main()
{
printf("before calling my MAPI function \n");
Fn();
printf("after calling my MAPI function \n");
return 0;
}

HRESULT SetMessageProps(SpIMessage &spMsg)
{
; // Message properties tag array
enum {SUBJECT, CLASS, BODY, MSG_DEL, MSG_PROPS };
SPropValue lpPropValueArray2[MSG_PROPS];
lpPropValueArray2[SUBJECT].ulPropTag = PR_SUBJECT;
CString Subject = "subject";

lpPropValueArray2[SUBJECT].Value.LPSZ = (LPTSTR)(LPCTSTR)Subject;
lpPropValueArray2[CLASS].ulPropTag = PR_MESSAGE_CLASS;
lpPropValueArray2[CLASS].Value.LPSZ = _T("IPM.Note" );

CString BodyText = "BodyText";
lpPropValueArray2[BODY].ulPropTag = PR_BODY;
lpPropValueArray2[BODY].Value.LPSZ = (LPTSTR)(LPCTSTR)BodyText;

lpPropValueArray2[MSG_DEL].ulPropTag = PR_DELETE_AFTER_SUBMIT;
lpPropValueArray2[MSG_DEL].Value.b = TRUE;

return spMsg->SetProps(MSG_PROPS,lpPropValueArray2,NULL);
}

HRESULT ResolveName(LPCTSTR Name, LPADRLIST *lpAdrList, LPADRBOOK pAddrBook)
{
HWND m_hWnd = NULL;

HRESULT hRes = S_OK;
ULONG ulUIParam = 0;
ULONG cbEID = 0L;
LPBYTE lpEID = NULL;
LPADRLIST pAdrList = NULL;

// Allocate memory for new SRowSet structure.
hRes = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList);

// If memory allocation fails, quit.
if ( FAILED ( hRes ) )
return hRes;
// Zero out allocated memory.
ZeroMemory ( pAdrList, CbNewSRowSet(1));
// Allocate memory for SPropValue structure that indicates what
// recipient properties will be set. To resolve a name that
// already exists in the Address book, this will always be 1.
hRes = MAPIAllocateBuffer( 1 * sizeof(SPropValue),
(LPVOID*) &(pAdrList->aEntries[0].rgPropVals));
// If memory allocation fails, quit.
if ( FAILED ( hRes ) )
{
MAPIFreeBuffer( pAdrList );
return hRes; // Zero out allocated memory.
}
ZeroMemory ( pAdrList -> aEntries[0].rgPropVals,
1 * sizeof(SPropValue) );
// Resolve name will take as many entries in the ADRLIST as you
// want to resolve, but each entry (ADRENTRY) can have only one
// property previously set by the client - this is usually
// PR_DISPLAY_NAME.
// How many recipients to resolve.
pAdrList->cEntries = 1;
// As far as I can tell this must always be 1L and will always
// equal the multiplier in the MAPIAllocateBuffer call above.
pAdrList->aEntries[0].cValues = 1L;
// Set the SPropValue members == the desired values. This should
// be PR_DISPLAY_NAME. You can substitute a display name with an
// alias to search for. You can search by alias and display names
// interchangeably in most address books.
pAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
pAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = (LPTSTR)Name;


// pAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_ENTRYID;
// ResolveName is kind enough to redimension this array for us and
// give back a fully filled out ADRLIST and ADRENTRY structures.
hRes = pAddrBook -> ResolveName ( (ULONG) m_hWnd,
MAPI_DIALOG , NULL, pAdrList );
if ( SUCCEEDED ( hRes ) )
{
*lpAdrList = pAdrList;
}
return hRes;
}

HRESULT CreateAttachment(SpIMessage &spMsg, LPSTREAM pStrm,
LPCTSTR Attachment )
{

SpIAttach pAtt;
ULONG ulAttNum;
HRESULT hr = S_OK;
if (SUCCEEDED(hr = spMsg->CreateAttach( NULL, (ULONG)0, &ulAttNum, &pAtt)))
{
enum {METHOD, RENDERING, FILENAME, NUM_ATT_PROPS};
SPropValue spvAttach[NUM_ATT_PROPS];
spvAttach[METHOD].ulPropTag = PR_ATTACH_METHOD;
spvAttach[METHOD].Value.l = ATTACH_BY_VALUE ;
spvAttach[RENDERING].ulPropTag = PR_RENDERING_POSITION;
spvAttach[RENDERING].Value.l = -1;
spvAttach[FILENAME].ulPropTag = PR_ATTACH_FILENAME;
spvAttach[FILENAME].Value.LPSZ = (LPTSTR)Attachment;
// Save the properties we have set on the attachment
if (SUCCEEDED(hr = pAtt ->SetProps( NUM_ATT_PROPS,
(LPSPropValue)&spvAttach, NULL)))
{
SpIStream pStream;

LARGE_INTEGER Zero = { 0 };

ULARGE_INTEGER Max;
Max.QuadPart = MAXLONGLONG;

ULARGE_INTEGER Result, Read, Written;


pStrm->Seek( Zero, SEEK_SET, & Result );

if( SUCCEEDED( hr = pAtt->OpenProperty( PR_ATTACH_DATA_BIN,
(LPIID) &IID_IStream,
0, MAPI_CREATE | MAPI_MODIFY, (LPUNKNOWN *)&pStream) ) )
{
if( SUCCEEDED( pStrm->CopyTo( pStream, Max, &Read, &Written ) ))
{
ASSERT( Read.QuadPart == Written.QuadPart );
}
pStream.Release();
}
hr = pAtt->SaveChanges(0);
}
}
return hr;
}


void MyItemDoMail(int Item, SpIMAPISession & SpSess, BOOL MailToXYZ /* =
FALSE */ )
{
SpIMAPIFolder SpFld;
SpIMsgStore SpMdb;
CString logString;

HWND m_hWnd = NULL;


ULONG cbInEntryID = 0;
LPENTRYID lpInEntryID = NULL;
ULONG ulObjType;
HRESULT hr = S_OK;

SpIMessage spMyMsg;
hr = HrMAPIFindDefaultMsgStore( SpSess, &cbInEntryID, &lpInEntryID);

logString.Format( _T("Creating COnDmdRptMsg (HrMAPIFindDefaultMsgStore) hr
= %x"), hr);
// MTRACE(logString);

if(SUCCEEDED(hr))
{
hr = SpSess->OpenMsgStore(0L, cbInEntryID, lpInEntryID, NULL,
MDB_WRITE | MAPI_DEFERRED_ERRORS, &SpMdb );

MAPIFreeBuffer(lpInEntryID);
logString.Format( _T("Creating COnDmdRptMsg (HrMAPIFindDefaultMsgStore) hr
= %x" ), hr);
// MTRACE(logString);

if(SUCCEEDED(hr))
{
cbInEntryID = 0;
lpInEntryID = NULL;

hr = HrMAPIFindOutbox( SpMdb, &cbInEntryID, &lpInEntryID);
logString.Format(_T("Creating COnDmdRptMsg (HrMAPIFindOutbox) hr = %x"),
hr);
// MTRACE(logString);

if(SUCCEEDED(hr))
{
hr = SpSess->OpenEntry( cbInEntryID,
lpInEntryID,
NULL,
MAPI_MODIFY,
&ulObjType,
(LPUNKNOWN FAR *)&SpFld);

MAPIFreeBuffer(lpInEntryID);

logString.Format( _T("Creating COnDmdRptMsg (OpenEntry) hr = %x" ), hr);
// MTRACE(logString);

if(SUCCEEDED(hr))
{
if( SUCCEEDED( hr = SpFld->CreateMessage(NULL, 0, &spMyMsg) ))
{
CString Destination = "(E-Mail Removed)";

SetMessageProps( spMyMsg );
if( !Destination.IsEmpty() )
{
LPADRLIST pal = NULL;
SpIAddrBook spAddrBook;

hr = SpSess->OpenAddressBook((ULONG)m_hWnd, NULL,
AB_NO_DIALOG, &spAddrBook );
if( SUCCEEDED( hr ) )
{
if( SUCCEEDED( ResolveName( Destination, &pal, spAddrBook ) ))
{

// We now have a resolved name. we need to add the MAPI_TO property
to it.
int i;
int NumProps = pal->aEntries[0].cValues + 1;
LPADRLIST pAdrList = NULL;
// Allocate memory for new SRowSet structure.
hr = MAPIAllocateBuffer(CbNewSRowSet(1),(LPVOID*) &pAdrList);

// If memory allocation fails, quit.
if ( FAILED ( hr) )
{
FreePadrlist( pal );
return;
}
// Zero out allocated memory.
ZeroMemory ( pAdrList, CbNewSRowSet(1));
hr = MAPIAllocateBuffer( NumProps * sizeof(SPropValue),
(LPVOID*) &(pAdrList->aEntries[0].rgPropVals));
ZeroMemory ( pAdrList-> aEntries[0].rgPropVals,
NumProps * sizeof(SPropValue) );

pAdrList->cEntries = 1;
pAdrList->aEntries[0].cValues = NumProps;

for( i = 0; i < NumProps -1; i++ )
{
pAdrList->aEntries[0].rgPropVals[i] =
pal->aEntries[0].rgPropVals[i];
}
pAdrList->aEntries[0].rgPropVals[ NumProps -1].ulPropTag =
PR_RECIPIENT_TYPE;
pAdrList->aEntries[0].rgPropVals[ NumProps -1].Value.ul = MAPI_TO;

spMyMsg->ModifyRecipients( MODRECIP_ADD , pAdrList );

// Remove memory references.
for( i = 0; i < NumProps -1; i++ )
{

pAdrList->aEntries[0].rgPropVals[i].ulPropTag = PROP_TAG(
PT_ERROR, 0 );
pAdrList->aEntries[0].rgPropVals[i].Value.ul = 0;
}
FreePadrlist( pAdrList );


FreePadrlist( pal );
}
}
}
LPSTREAM pStrm;

if( SUCCEEDED( ::CreateStreamOnHGlobal( NULL, TRUE, &pStrm ) ) )
{
if( SUCCEEDED( hr = CreateAttachment( spMyMsg, pStrm, "filename.txt"
) ))
{
ULONG Token;
enum { MSG_STATUS, MSG_FLAGS, MSG_ACCESS, MSG_CLASS, NUM_PROPS };
const SizedSPropTagArray( NUM_PROPS, taProp ) = {NUM_PROPS,
PR_MSG_STATUS,
PR_MESSAGE_FLAGS,
PR_ACCESS,
PR_MESSAGE_CLASS };

SpSPropValue SpVal;
ULONG ulCnt = 0;
hr = spMyMsg->SaveChanges( FORCE_SAVE | KEEP_OPEN_READWRITE );

hr = spMyMsg->GetProps((LPSPropTagArray)&taProp, 0,
&ulCnt, &SpVal);

if( hr == S_OK )
{
printf("before PrepareForm \n");
::AfxMessageBox( "before PrepareForm", MB_OK );
SpSess->PrepareForm( NULL, spMyMsg, &Token );
printf("after PrepareForm \n");
::AfxMessageBox( "after PrepareForm", MB_OK );

spMyMsg.Release();
printf("after release2 \n");
::AfxMessageBox( "after release2", MB_OK );

HRESULT hr2 = S_OK;
hr2 = SpSess->ShowForm( (LPARAM)m_hWnd, SpMdb, SpFld, NULL,
Token, NULL, MAPI_NEW_MESSAGE,
SpVal[ MSG_STATUS].Value.ul,
SpVal[ MSG_FLAGS].Value.ul,
SpVal[ MSG_ACCESS].Value.ul,
SpVal[ MSG_CLASS].Value.LPSZ );


DWORD dw = GetLastError();
char str2[180];
sprintf(str2,"error. %d \n",dw);
::AfxMessageBox( str2, MB_OK );

if(hr2 != S_OK)
{
char str[180];
sprintf(str,"got screwed. %x \n",hr2);
::AfxMessageBox( str, MB_OK );
}
else
{
char str[180];
sprintf(str,"fine. %x \n",hr2);
::AfxMessageBox( str, MB_OK );
}

printf("after ShowForm \n");
::AfxMessageBox( "after ShowForm", MB_OK );
}
}
}
}

}
}
}
}


}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sending email generates an "object not found" message. How to fix =?Utf-8?B?ZmxpbnQ=?= Microsoft Outlook Installation 5 22nd Sep 2008 01:39 AM
when I send/receive message "operation failed...object not found" =?Utf-8?B?THVrZUJvd2Vycw==?= Microsoft Outlook Discussion 1 9th Dec 2006 05:52 PM
Error message "an object can't be found" when sending mail =?Utf-8?B?VmlrZXM=?= Microsoft Outlook Installation 7 21st Feb 2006 02:37 AM
Sending Email get message "Operation failed" object not found =?Utf-8?B?RGF2aWR4?= Microsoft Outlook Discussion 2 14th Feb 2005 07:59 PM
Re: error message "The operation failed, an object could not be found" Jeff Stephenson [MSFT] Microsoft Outlook 0 25th Mar 2004 04:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 AM.