Article ID: 170601
Article Last Modified on 8/18/2005
HRESULT ShowForm ( LPMAPISESSION m_pSession,
LPMAPIFOLDER pFolder,
HWND m_hWnd )
{
HRESULT hRes = S_OK;
enum {MSG_CLASS, MSG_STATUS, MSG_FLAGS, MSG_ACCESS };
LPSPropValue pProps = NULL;
ULONG cProps,
ulObjType;
LPMESSAGE pMsg = NULL;
LPMAPIFORMMGR pFormMgr = NULL;
LPMAPIFORMINFO pFormInfo = NULL;
LPPERSISTMESSAGE pPersistMessage = NULL;
ULONG ulMessageToken = 0L,
cValues = 0L;
LPSPropValue pPropsMsg = NULL;
// Message properties tag array
SizedSPropTagArray ( 4, sptMsgProps ) = { 4,
PR_MESSAGE_CLASS,
PR_MSG_STATUS,
PR_MESSAGE_FLAGS,
PR_ACCESS };
hRes = pFolder -> CreateMessage ( NULL, 0L, &pMsg );
if ( SUCCEEDED ( hRes ) )
hRes = pMsg -> SaveChanges ( KEEP_OPEN_READWRITE );
// Need to know certain properties of message for ShowForm.
hRes = pMsg -> GetProps ( (LPSPropTagArray)&sptMsgProps,
0L,
&cValues,
&pPropsMsg );
// Get an IFormManager interface pointer
if ( FAILED ( hRes = MAPIOpenFormMgr ( m_pSession, &pFormMgr ) ) )
goto Quit;
// Use the message class of the message to resolve to the correct
// message class.
if ( FAILED ( hRes = pFormMgr->ResolveMessageClass (
pPropsMsg[0].Value.lpszA,
MAPIFORM_EXACTMATCH,
NULL,
&pFormInfo ) ) )
goto Quit;
// Create an instance of the form and store is in an
// IPersistMessage interface pointer.
if ( FAILED ( hRes = pFormMgr -> CreateForm ( m_hWnd,
0L,
pFormInfo,
IID_IPersistMessage,
(LPVOID*) &pPersistMessage ) ) )
goto Quit;
// Call the IPersistMessage::Save method.
pPersistMessage -> Save ( pMsg, TRUE );
// Prepare the form to be loaded by getting its token.
if ( FAILED ( hRes = m_pSession -> PrepareForm ( &IID_IMessage,
pMsg,
&ulMessageToken ) ) )
goto Quit;
// Call the session object's ShowForm method. Each of the
// properties we retreived above will be used in each of the
// corresponding parameters in this call.
if ( FAILED ( m_pSession -> ShowForm (
m_hWnd,
m_pMDB,
pFolder,
&IID_IMessage,
ulMessageToken,
0L,
MAPI_NEW_MESSAGE,
pPropsMsg[MSG_STATUS].Value.l,
pPropsMsg[MSG_FLAGS].Value.l,
pPropsMsg[MSG_ACCESS].Value.l,
pPropsMsg[MSG_CLASS].Value.lpszA)))
goto Quit;
// Clean up and release all objects no longer needed in this
// method. Be sure to return the value of hRes to the caller.
Quit:
if ( NULL != pMsg )
{
pMsg -> Release ( );
pMsg = NULL;
}
if ( NULL != pFormMgr )
{
pFormMgr -> Release ( );
pFormMgr = NULL;
}
if ( NULL != pFormInfo )
{
pFormInfo -> Release ( );
pFormInfo = NULL;
}
if ( NULL != pPersistMessage )
{
pPersistMessage -> Release ( );
pPersistMessage = NULL;
}
return hRes;
}
Keywords: kbhowto kbmsg KB170601