CMessageStore::ReplaceMessage Method  
 
BOOL ReplaceMessage(
  LONG nMessageId,  
  CMailMessage& mailMessage  
);
BOOL ReplaceMessage(
  LONG nMessageId,  
  HMESSAGE hMessage  
);

The MimeReplaceStoredMessage function replaces the contents of the specified message in a message store.

Parameters

nMessageId
An integer value which specifies the message number that should be replaced.
mailMessage
A CMailMessage object which references the message that will be stored.
hMessage
Handle to the message that will be stored.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call MimeGetLastError.

Remarks

The ReplaceMessage method replaces the specified message with a new message. The message number may be a message that has been previously marked for deletion. It is important to note that the change will not be reflected in the physical storage file until it has been closed. If the application needs to replace messages in the message store, it is recommended that the file be opened for exclusive access using the MIME_STORAGE_LOCK option.

Example

CMailMessage mailMessage;

// Compose a new message
mailMessage.ComposeMessage(lpszSender,
                           lpszRecipient,
                           NULL,
                           lpszSubject,
                           lpszMessage);

CMessageStore mailStorage;

if (mailStorage.OpenFile(lpszFileName, MIME_STORAGE_WRITE))
{
    LONG nLastMessage = 0;

    // Get the last message number in the message store
    mailStorage.GetMessageCount(&nLastMessage);

    if (nLastMessage > 0)
    {
        // Replace the last message in the message store
        if (!mailStorage.ReplaceMessage(nLastMessage, mailMessage))
        {
            // We were unable to replace the message
        }
    }

    // Close the message store
    mailStorage.CloseFile();
}

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csmsgv10.lib

See Also

FindMessage, GetMessage, DeleteMessage, StoreMessage