- Joined
- May 27, 2008
- Messages
- 1
- Reaction score
- 0
Hi
i am programming Extended MAPI in C++. and trying to save message items as msg files.
But i am getting error "E_NOINTERFACE" each time i try to execute CopyTo method of IMessage.
any idea about the solution here is my source code ..
#include <initguid.h> //this is needed,
#define USES_IID_IMessage
#include <mapiguid.h> //then this
#include <mapix.h>
#include <mapiutil.h>
#include <mspst.h>
{
[font="]HRESULT hRes = S_OK;[/font]
[font="] LPSPropValue pSubject = NULL;[/font]
[font="] LPSTORAGE pStorage = NULL;[/font]
[font="] LPMSGSESS pMsgSession = NULL;[/font]
[font="] LPMESSAGE pIMsg = NULL;[/font]
[font="] SizedSPropTagArray ( 7, excludeTags );[/font]
[font="] char szPath[_MAX_PATH] = {0};[/font]
[font="] strcpy(szPath, m_outPath.GetBuffer(10));[/font]
[font="] char strAttachmentFile[_MAX_PATH];[/font]
[font="] LPWSTR lpWideCharStr = NULL;[/font]
[font="] ULONG cbStrSize = 0L;[/font]
[font="] [/font]
[font="] // create the file name in the directory where "TMP" is defined[/font]
[font="] // with subject as the filename and ".msg" extension.[/font]
[font="] [/font]
[font="] // get temp file directory[/font]
[font="] //GetTempPath(_MAX_PATH, szPath);[/font]
[font="] [/font]
[font="] // get subject line of message to copy. This will be used as the[/font]
[font="] // new file name.[/font]
[font="] HrGetOneProp( pMessage, PR_SUBJECT, &pSubject );[/font]
[font="] [/font]
[font="] // fuse path, subject, and suffix into one string[/font]
[font="] char name[MAX_PATH];[/font]
[font="] memset(name, 0, MAX_PATH);[/font]
[font="] [/font]
[font="] itoa(count, name, 10);[/font]
[font="] [/font]
[font="] strcpy(strAttachmentFile, szPath);[/font]
[font="] //strcat ( strAttachmentFile, "\\"); [/font]
[font="] strcat ( strAttachmentFile, name); [/font]
[font="] strcat ( strAttachmentFile, ".msg");[/font]
[font="] [/font]
[font="] // get memory allocation function[/font]
[font="] LPMALLOC pMalloc = MAPIGetDefaultMalloc();[/font]
[font="] [/font]
[font="] // Convert new file name to WideChar[/font]
[font="] cbStrSize = MultiByteToWideChar (CP_ACP,[/font]
[font="] MB_PRECOMPOSED,[/font]
[font="] strAttachmentFile,[/font]
[font="] -1, lpWideCharStr, 0);[/font]
[font="] [/font]
[font="] MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),[/font]
[font="] (LPVOID *)&lpWideCharStr );[/font]
[font="] [/font]
[font="] MultiByteToWideChar (CP_ACP,[/font]
[font="] MB_PRECOMPOSED,[/font]
[font="] strAttachmentFile,[/font]
[font="] -1, lpWideCharStr, cbStrSize );[/font]
[font="] [/font]
[font="] // create compound file[/font]
[font="] hRes = ::StgCreateStorageEx(lpWideCharStr,[/font]
[font="] STGM_READWRITE |[/font]
[font="] STGM_TRANSACTED |[/font]
[font="] STGM_CREATE, STGFMT_STORAGE, 0, NULL, NULL, IID_IStorage, (void**)&pStorage);[/font]
[font="] [/font]
[font="] // Open an IMessage session.[/font]
[font="] hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession); [/font]
[font="] [/font]
[font="] // Open an IMessage interface on an IStorage object[/font]
[font="] hRes = ::OpenIMsgOnIStg(pMsgSession,[/font]
[font="] MAPIAllocateBuffer,[/font]
[font="] MAPIAllocateMore,[/font]
[font="] MAPIFreeBuffer,[/font]
[font="] pMalloc,[/font]
[font="] NULL,[/font]
[font="] pStorage,[/font]
[font="] NULL, 0, 0, &pIMsg);[/font]
[font="] [/font]
[font="] // write the CLSID to the IStorage instance - pStorage. This will[/font]
[font="] // only work with clients that support this compound document type[/font]
[font="] // as the storage medium. If the client does not support[/font]
[font="] // CLSID_MailMessage as the compound document, you will have to use[/font]
[font="] // the CLSID that it does support.[/font]
[font="] hRes = WriteClassStg(pStorage, CLSID_MailMessage );[/font]
[font="] [/font]
[font="] // Specify properties to exclude in the copy operation. These are[/font]
[font="] // the properties that Exchange excludes to save bits and time.[/font]
[font="] // Should not be necessary to exclude these, but speeds the process[/font]
[font="] // when a lot of messages are being copied.[/font]
[font="] excludeTags.cValues = 7;[/font]
[font="] excludeTags.aulPropTag[0] = PR_ACCESS;[/font]
[font="] excludeTags.aulPropTag[1] = PR_BODY;[/font]
[font="] excludeTags.aulPropTag[2] = PR_RTF_SYNC_BODY_COUNT;[/font]
[font="] excludeTags.aulPropTag[3] = PR_RTF_SYNC_BODY_CRC;[/font]
[font="] excludeTags.aulPropTag[4] = PR_RTF_SYNC_BODY_TAG;[/font]
[font="] excludeTags.aulPropTag[5] = PR_RTF_SYNC_PREFIX_COUNT;[/font]
[font="] excludeTags.aulPropTag[6] = PR_RTF_SYNC_TRAILING_COUNT;[/font]
[font="] [/font]
[font="] // copy message properties to IMessage object opened on top of[/font]
[font="] // IStorage.+[/font]
[font="] [/font]
[font="] //HRESULT hResult = CoCreateInstance (myCLSID, NULL, CLSCTX_INPROC_SERVER, myCLSID, (LPVOID*)&myMessage);[/font]
[font="] [/font]
[font="] hRes = pMessage->CopyTo(0, NULL,[/font]
[font="] (LPSPropTagArray)&excludeTags,[/font]
[font="] NULL, NULL,[/font]
[font="] (LPIID)&IID_IMessage,[/font]
[font="] pIMsg, 0, NULL );[/font]
[font="] [/font]
[font="] if (hRes == S_OK)[/font]
[font="] {[/font]
[font="] // save changes to IMessage object.[/font]
[font="] if (pIMsg)[/font]
[font="] hRes = pIMsg->SaveChanges( KEEP_OPEN_READWRITE );[/font]
[font="] [/font]
[font="] // save changes in storage of new doc file[/font]
[font="] hRes = pStorage->Commit(STGC_DEFAULT);[/font]
[font="] count++;[/font]
[font="] }[/font]
[font="] [/font]
[font="] [/font]
[font="] // free objects and clean up memory[/font]
[font="] MAPIFreeBuffer ( lpWideCharStr );[/font]
[font="] pStorage->Release();[/font]
[font="] pIMsg->Release();[/font]
[font="] CloseIMsgSession ( pMsgSession );[/font]
[font="] [/font]
[font="] pStorage = NULL;[/font]
[font="] pIMsg = NULL;[/font]
[font="] pMsgSession = NULL;[/font]
[font="] lpWideCharStr = NULL;[/font]
[font="] [/font]
[font="] //count++;[/font]
[font="] return hRes;[/font]
[font="]}[/font]
i am programming Extended MAPI in C++. and trying to save message items as msg files.
But i am getting error "E_NOINTERFACE" each time i try to execute CopyTo method of IMessage.
any idea about the solution here is my source code ..
#include <initguid.h> //this is needed,
#define USES_IID_IMessage
#include <mapiguid.h> //then this
#include <mapix.h>
#include <mapiutil.h>
#include <mspst.h>
{
[font="]HRESULT hRes = S_OK;[/font]
[font="] LPSPropValue pSubject = NULL;[/font]
[font="] LPSTORAGE pStorage = NULL;[/font]
[font="] LPMSGSESS pMsgSession = NULL;[/font]
[font="] LPMESSAGE pIMsg = NULL;[/font]
[font="] SizedSPropTagArray ( 7, excludeTags );[/font]
[font="] char szPath[_MAX_PATH] = {0};[/font]
[font="] strcpy(szPath, m_outPath.GetBuffer(10));[/font]
[font="] char strAttachmentFile[_MAX_PATH];[/font]
[font="] LPWSTR lpWideCharStr = NULL;[/font]
[font="] ULONG cbStrSize = 0L;[/font]
[font="] [/font]
[font="] // create the file name in the directory where "TMP" is defined[/font]
[font="] // with subject as the filename and ".msg" extension.[/font]
[font="] [/font]
[font="] // get temp file directory[/font]
[font="] //GetTempPath(_MAX_PATH, szPath);[/font]
[font="] [/font]
[font="] // get subject line of message to copy. This will be used as the[/font]
[font="] // new file name.[/font]
[font="] HrGetOneProp( pMessage, PR_SUBJECT, &pSubject );[/font]
[font="] [/font]
[font="] // fuse path, subject, and suffix into one string[/font]
[font="] char name[MAX_PATH];[/font]
[font="] memset(name, 0, MAX_PATH);[/font]
[font="] [/font]
[font="] itoa(count, name, 10);[/font]
[font="] [/font]
[font="] strcpy(strAttachmentFile, szPath);[/font]
[font="] //strcat ( strAttachmentFile, "\\"); [/font]
[font="] strcat ( strAttachmentFile, name); [/font]
[font="] strcat ( strAttachmentFile, ".msg");[/font]
[font="] [/font]
[font="] // get memory allocation function[/font]
[font="] LPMALLOC pMalloc = MAPIGetDefaultMalloc();[/font]
[font="] [/font]
[font="] // Convert new file name to WideChar[/font]
[font="] cbStrSize = MultiByteToWideChar (CP_ACP,[/font]
[font="] MB_PRECOMPOSED,[/font]
[font="] strAttachmentFile,[/font]
[font="] -1, lpWideCharStr, 0);[/font]
[font="] [/font]
[font="] MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),[/font]
[font="] (LPVOID *)&lpWideCharStr );[/font]
[font="] [/font]
[font="] MultiByteToWideChar (CP_ACP,[/font]
[font="] MB_PRECOMPOSED,[/font]
[font="] strAttachmentFile,[/font]
[font="] -1, lpWideCharStr, cbStrSize );[/font]
[font="] [/font]
[font="] // create compound file[/font]
[font="] hRes = ::StgCreateStorageEx(lpWideCharStr,[/font]
[font="] STGM_READWRITE |[/font]
[font="] STGM_TRANSACTED |[/font]
[font="] STGM_CREATE, STGFMT_STORAGE, 0, NULL, NULL, IID_IStorage, (void**)&pStorage);[/font]
[font="] [/font]
[font="] // Open an IMessage session.[/font]
[font="] hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession); [/font]
[font="] [/font]
[font="] // Open an IMessage interface on an IStorage object[/font]
[font="] hRes = ::OpenIMsgOnIStg(pMsgSession,[/font]
[font="] MAPIAllocateBuffer,[/font]
[font="] MAPIAllocateMore,[/font]
[font="] MAPIFreeBuffer,[/font]
[font="] pMalloc,[/font]
[font="] NULL,[/font]
[font="] pStorage,[/font]
[font="] NULL, 0, 0, &pIMsg);[/font]
[font="] [/font]
[font="] // write the CLSID to the IStorage instance - pStorage. This will[/font]
[font="] // only work with clients that support this compound document type[/font]
[font="] // as the storage medium. If the client does not support[/font]
[font="] // CLSID_MailMessage as the compound document, you will have to use[/font]
[font="] // the CLSID that it does support.[/font]
[font="] hRes = WriteClassStg(pStorage, CLSID_MailMessage );[/font]
[font="] [/font]
[font="] // Specify properties to exclude in the copy operation. These are[/font]
[font="] // the properties that Exchange excludes to save bits and time.[/font]
[font="] // Should not be necessary to exclude these, but speeds the process[/font]
[font="] // when a lot of messages are being copied.[/font]
[font="] excludeTags.cValues = 7;[/font]
[font="] excludeTags.aulPropTag[0] = PR_ACCESS;[/font]
[font="] excludeTags.aulPropTag[1] = PR_BODY;[/font]
[font="] excludeTags.aulPropTag[2] = PR_RTF_SYNC_BODY_COUNT;[/font]
[font="] excludeTags.aulPropTag[3] = PR_RTF_SYNC_BODY_CRC;[/font]
[font="] excludeTags.aulPropTag[4] = PR_RTF_SYNC_BODY_TAG;[/font]
[font="] excludeTags.aulPropTag[5] = PR_RTF_SYNC_PREFIX_COUNT;[/font]
[font="] excludeTags.aulPropTag[6] = PR_RTF_SYNC_TRAILING_COUNT;[/font]
[font="] [/font]
[font="] // copy message properties to IMessage object opened on top of[/font]
[font="] // IStorage.+[/font]
[font="] [/font]
[font="] //HRESULT hResult = CoCreateInstance (myCLSID, NULL, CLSCTX_INPROC_SERVER, myCLSID, (LPVOID*)&myMessage);[/font]
[font="] [/font]
[font="] hRes = pMessage->CopyTo(0, NULL,[/font]
[font="] (LPSPropTagArray)&excludeTags,[/font]
[font="] NULL, NULL,[/font]
[font="] (LPIID)&IID_IMessage,[/font]
[font="] pIMsg, 0, NULL );[/font]
[font="] [/font]
[font="] if (hRes == S_OK)[/font]
[font="] {[/font]
[font="] // save changes to IMessage object.[/font]
[font="] if (pIMsg)[/font]
[font="] hRes = pIMsg->SaveChanges( KEEP_OPEN_READWRITE );[/font]
[font="] [/font]
[font="] // save changes in storage of new doc file[/font]
[font="] hRes = pStorage->Commit(STGC_DEFAULT);[/font]
[font="] count++;[/font]
[font="] }[/font]
[font="] [/font]
[font="] [/font]
[font="] // free objects and clean up memory[/font]
[font="] MAPIFreeBuffer ( lpWideCharStr );[/font]
[font="] pStorage->Release();[/font]
[font="] pIMsg->Release();[/font]
[font="] CloseIMsgSession ( pMsgSession );[/font]
[font="] [/font]
[font="] pStorage = NULL;[/font]
[font="] pIMsg = NULL;[/font]
[font="] pMsgSession = NULL;[/font]
[font="] lpWideCharStr = NULL;[/font]
[font="] [/font]
[font="] //count++;[/font]
[font="] return hRes;[/font]
[font="]}[/font]