MimeExportMessageEx Function  
 
BOOL WINAPI MimeExportMessageEx(
  HMESSAGE hMessage,  
  DWORD dwExportMode,  
  DWORD dwExportOptions,  
  LPVOID lpvMessage,  
  LPDWORD lpdwMessageSize  
);

The MimeExportMessageEx function exports the message to a file, the system clipboard or global memory buffer.

Parameters

hMessage
Handle to the message.
dwExportMode
An unsigned long integer which specifies how the message contents will be exported. It may be one of the following values:
Constant Description
MIME_EXPORT_DEFAULT The default export mode. If the lpvMessage parameter is NULL, then the contents of the message will be copied to the system clipboard. Otherwise, the lpvMessage parameter is a pointer to a null-terminated string which specifies the name of a file to store the message in.
MIME_EXPORT_FILE The lpvMessage parameter is a pointer to a null-terminated string which specifies the name of a file to store the message in. If the file does not exist, it will be created. Otherwise the file will be overwritten with the contents of the message.
MIME_EXPORT_CLIPBOARD The contents of the message is copied to the system clipboard. The lpvMessage parameter is ignored.
MIME_EXPORT_MEMORY The contents of the message is copied to a local buffer. The lpvMessage parameter must point to a byte array which will contain the message contents when the function returns. The lpdwMessageSize parameter must be initialized to the maximum size of the buffer and will contain the number of bytes copied to the buffer when the function returns.
MIME_EXPORT_HGLOBAL The contents of the message is stored in a global memory buffer. The lpvMessage parameter must point to a global memory handle which will reference the message buffer when the function returns. The lpdwMessageSize parameter will contain the number of bytes allocated for the message. The client application is responsible for releasing the memory handle when the message contents are no longer needed.
dwExportOptions
An unsigned long integer which specifies how the message will be exported. The following values may be combined using a bitwise Or operator:
Constant Description
MIME_OPTION_DEFAULT The default export options. The headers for the message are written out in a specific consistent order, with custom headers written to the end of the header block regardless of the order in which they were set or imported from another message. If the message contains Bcc, Received, Return-Path, Status or X400-Received header fields, they will not be exported.
MIME_OPTION_KEEPORDER The original order in which the message header fields were set or imported are preserved when the message is exported.
MIME_OPTION_ALLHEADERS All headers, including the Received, Return-Path, Status and X400-Received header fields will be exported. Normally these headers are not exported because they are only used by the mail transport system. This option can be useful when exporting a message to be stored on the local system, but should not be used when exporting a message to be delivered to another user.
lpvMessage
A pointer to a null-terminated string, a byte buffer or a global memory handle. The dwExportMode parameter determines how this pointer is used by the function.
lpdwMessageSize
A pointer to an unsigned long integer value which will contain the size of the message when the function exits. This parameter may be NULL if you do not require this information, except if the dwExportMode parameter is MIME_EXPORT_MEMORY. In this case, the parameter must point to a value initialized with the maximum size of the byte buffer that has been passed to the function.

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.

Example

The following example exports the contents of a message to a global memory buffer:

HGLOBAL hgblMessage = NULL;
DWORD dwMessageSize = 0;

bResult = MimeExportMessageEx(hMessage,
                              MIME_EXPORT_HGLOBAL,
                              MIME_OPTION_DEFAULT,
                              &hgblMessage,
                              &dwMessageSize);

if (bResult)
{
    LPBYTE lpMessage = (LPBYTE)GlobalLock(hgblMessage);

    if (lpMessage)
    {
        // Process the contents of the message
    }

    GlobalUnlock(hgblMessage);
    GlobalFree(hgblMessage);
}

Requirements

Client: Requires Windows 7, Windows Vista or Windows XP.
Server: Requires Windows Server 2008 or Windows Server 2003.
Header: Include cstools7.h.
Library: Use csmsgav7.lib.
Unicode: Implemented as Unicode and ANSI versions.

See Also

MimeCreateMessage, MimeExportMessage, MimeImportMessage, MimeImportMessageEx, MimeSetExportOptions