MimeGetMessageHeaderEx Function  
 
INT WINAPI MimeGetMessageHeaderEx(
  HMESSAGE hMessage,  
  INT nMessagePart,  
  LPCTSTR lpszHeader,  
  LPTSTR lpszValue,  
  INT nMaxValue,  
  DWORD dwReserved  
);

The MimeGetMessageHeaderEx copies the value of the specified header into a string buffer.

Parameters

hMessage
Handle to the message.
nMessagePart
An integer value which specifies which part of the message to return the header value from. A value of zero returns a header value from the main message header, while a value greater than zero returns the header value from that specific part of a multipart message. A value of -1 specifies that the header value should be returned from the current message part.
lpszHeader
Pointer to the null-terminated string which specifies the message header.
lpszValue
A pointer to a string buffer which will contain the value of the specified header when the function returns. If this parameter is NULL, the function will return the length of the header value without copying the data. This is useful for determining the length of a header value so that a string buffer can be allocated and passed to a subsequent call to the function.
nMaxValue
An integer value which specifies the maximum number of characters that can be copied to the string buffer, including the terminating null byte. If the lpszValue parameter is NULL, this value should be zero.
dwReserved
A reserved parameter. This value should always be zero.

Return Value

If the function succeeds, the return value is the number of bytes copied into the string buffer, not including the terminating null byte. If the lpszValue parameter is NULL, the return value is the length of the header value. If the header field does not exist, a value of zero is returned. If an invalid pointer or message part is specified, a value of MIME_ERROR is returned. To get extended error information, call MimeGetLastError.

Example

LPTSTR lpszValue = NULL;
INT cchValue = 0;

// Determine the length of the To header field
cchValue = MimeGetMessageHeaderEx(hMessage, 0, _T("To"), NULL, 0);

// If the header field exists, allocate a string buffer
// and copy the value into the buffer
if (cchValue > 0)
{
    lpszValue = (LPTSTR)LocalAlloc(LPTR, cchValue + 1);
    MimeGetMessageHeaderEx(hMessage,
                           0,
                           _T("To"),
                           lpszValue,
                           cchValue + 1);
}

// After the string buffer has been used, release the
// memory that was allocated for it
if (lpszValue)
{
    LocalFree((HLOCAL)lpszValue);
    lpszValue = NULL;
}

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

MimeEnumMessageHeaders, MimeGetFirstMessageHeader, MimeGetMessageHeader, MimeGetMessagePart, MimeGetNextMessageHeader, MimeParseHeader, MimeSetMessageHeader, MimeSetMessagePart