共用方式為


PROPID_M_BODY_SIZE

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

(Read-only.) The PROPID_M_BODY_SIZE property indicates the size of the message body.

Property ID

PROPID_M_BODY_SIZE

Type Indicator

VT_UI4

MQPROPVARIANT Field

ulVal

Property Value

The size of the message body returned by PROPID_M_BODY.

Remarks

PROPID_M_BODY_SIZE is used only by the receiving application to retrieve the size of a message. It is used to determine the size of a message body before the message body is retrieved.

Each Message Queuing message can have no more than 4 MB of data.

To retrieve the message body from a message, specify PROPID_M_BODY_SIZE and PROPID_M_BODY in the MQMSGPROPS structure. Then call MQReceiveMessage or MQReceiveMessageByLookupId and examine the returned values. The type indicator of this property can be set to VT_UI4 or VT_NULL. If you set the type indicator to VT_NULL, Message Queuing automatically changes the type indicator to VT_UI4 during the function call.

When the function call succeeds, first test the returned value of PROPID_M_BODY_SIZE to see if a message body exists. A returned value of 0 indicates that no body is attached to the message. A non-0 returned value indicates that a message body was returned by PROPID_M_BODY.

If MQReceiveMessage or MQReceiveMessageByLookupId fails, returning an MQ_ERROR_BUFFER_OVERFLOW error, use the returned value of PROPID_M_BODY_SIZE to reallocate the message body buffer and call the applicable function again. The memory allocated for the buffer must be freed by the application after it is no longer needed.

Equivalent COM Property

With COM components, the equivalent property for retrieving the size of the message body is MSMQMessage.BodyLength.

Example Code

The following code fragment shows how PROPID_M_BODY_SIZE and PROPID_M_BODY are specified in arrays that can be used to initialize an MQMSGPROPS structure when retrieving the message body:

aMsgPropID[i] = PROPID_M_BODY_SIZE;            // Property ID  
aMsgPropVar[i].vt = VT_NULL;                   // Type indicator  
i++  
  
ULONG ulBodyBufferSize = 1024;  
UCHAR * pucBodyBuffer = NULL;  
pucBodyBuffer = (UCHAR *)malloc(ulBodyBufferSize);  
if (pucBodyBuffer == NULL)  
{  
  return MQ_ERROR_INSUFFICIENT_RESOURCES;  
}  
memset(pucBodyBuffer, 0, ulBodyBufferSize);  
aMsgPropID[i] = PROPID_M_BODY;                 // Property ID  
aMsgPropVar[i].vt = VT_VECTOR | VT_UI1;        // Type indicator  
aMsgPropVar[i].caub.pElems = (UCHAR*)pucBodyBuffer;  
aMsgPropVar[i].caub.cElems = ulBodyBufferSize;  
i++  

See Also

Message Properties
MQMSGPROPS
MQReceiveMessage
MQReceiveMessageByLookupId
PROPID_M_BODY