none
Byte to LpMessage RRS feed

  • Question

  • Hi guys,

    Do any of you guys happened to know how to convert a byte array into LpMessage object type in extended MAPI? Assuming that the byte array received is from the sender's LpMessage object. 

    I've tried the solutions in http://microsoft.public.win32.programmer.messaging.narkive.com/rvjVpJSC/bytes-in-memory-convert-to-lpmessage-and-read-pr-body However, i still get an empty LpMessage object (As in without a subject and etc). 

    Monday, August 5, 2013 4:05 AM

Answers

All replies

  • Please show your code.

    When you save the array to a file, does Outlook recognize it as a valid MSG file?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, August 5, 2013 6:03 PM
  • When I save the array to a file, it however does manage to recognized it as a valid MSG file. 

    FILE* file = fopen( "C:\\myfile.msg", "wb" );
    fwrite( byteBuf, 1, BUFFER_SIZE, file );



    • Edited by ming_sa Tuesday, August 6, 2013 1:53 AM
    Tuesday, August 6, 2013 1:21 AM
  • //Method takes 2 parameter, (LPBYTE buffer,DWORD bufferLength)
            LPMESSAGE m_message = NULL;
    	LPSTORAGE pStorage = NULL;
    	ILockBytes *LB = NULL;
    	LPMSGSESS pMsgSession =  NULL;
    	
    	LPMALLOC pMalloc = MAPIGetDefaultMalloc();
    	if(pMalloc == NULL) return FALSE;
    	
    	HRESULT hRes = CreateILockBytesOnHGlobal(NULL, TRUE, &LB);
    	if(SUCCEEDED(hRes))
    	{
    		hRes = ::StgCreateDocfileOnILockBytes(LB,STGM_TRANSACTED|STGM_READWRITE |STGM_CREATE, 0, &pStorage); //Tried setting it to read only, but it still can't go through.
    		pStorage->Commit(STGC_DEFAULT);
    		if (SUCCEEDED(hRes))
    		{
    			WriteClassStg(pStorage, CLSID_MailMessage);
    			ULARGE_INTEGER offset = {0};
    			ULONG writtenbytes = 0;
    			LB->WriteAt(offset, buffer, bufferLength, &writtenbytes);
    			if (writtenbytes == bufferLength)
    			{
    				pStorage->Commit(STGC_DEFAULT);
    				
    				if (SUCCEEDED (hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession)))
    				{
    					if (SUCCEEDED(hRes = ::OpenIMsgOnIStg(pMsgSession,MAPIAllocateBuffer, MAPIAllocateMore,MAPIFreeBuffer,pMalloc, NULL, pStorage, NULL, 0,0, &m_message)))
    					{
    										
    			return m_message;
    						
    					}
    				}
    			}
    		}
    	}

    Tuesday, August 6, 2013 2:56 AM
  • Can you just save the array to a temporary file and then open it using StgOpenStorage/OpenIMsgOnIStg?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Thursday, August 8, 2013 5:07 PM