How to send MSMQ messages over 4MB in size - #1: Using MQRTLARGE.DLL

As writing a blog that covered all the options might get a bit cumbersome (like my Insufficient Resources post), I'm splitting the different approaches up into their own separate posts. The first will be about using the BizTalk Message Queuing Large Message Extension (MQRTLARGE.DLL).

To use the DLL you need to make use of the BizTalk Message Queuing Large Message Extension API, an add-on for native message queuing.

"Native message queuing cannot process a message with a body larger than 4 megabytes (MB). However, Microsoft® BizTalk® Server 2004 includes an add-on for native message queuing that permits processing messages larger than 4MB. This add-on is delivered as the Mqrtlarge.dll file, and exposes the MQSendLargeMessage and MQReceiveLargeMessage application programming interfaces (APIs), and the analogous COM model. These functions are implemented as standard message queuing APIs, MQSendMessage and MQReceiveMessage respectively.

To participate in large message exchanges, the message queuing computer must have the Mqrtlarge.dll file installed, and the message queuing application should use the add-on APIs. Otherwise, complete messages will be fragmented."

Although the API has "BizTalk" in the name it doesn't mean you must have BizTalk installed anywhere to send large messages. All you need is code inside the application that calls MQRTLARGE.DLL "*Large*" API versions instead of the regular MSMQ API. Saying that, though, the DLL was ONLY shipped with BizTalk to provide large message access and so it is not supported in non-BizTalk configurations - just because it seems to work doesn't mean Microsoft has tested and approved it.

This MSDN article Large Message to MSMQT (BizTalk Server Sample) has a sample demonstration on sending messages to MSMQ/T which can be used for ideas on writing your own MSMQ-MSMQ application.
Note: there are some minor code omissions in the sample that are documented in KnowledgeBase article 897294:

You may receive a "System.Runtime.InteropServices.COMException" exception error when you try to send a large message by using the Large Message to MSMQT sample application in BizTalk Server 2004

To get hold of the DLL, you need to download the BizTalk Server 2004 SDK.
Note: The link is just for the update to the SDK and, when you run the EXE, it will complain if BizTalk is not already installed. So (assuming you don't have BizTalk installed), with the "unable to find the BizTalk Server 2004 install path" dialogue box still on the screen, have a look in your Temp directory for the extracted files. MQRTLARGE.DLL should be in the <something>.TMP\Samples\Adapters\MSMQTLarge\LargeApi sub-directory.

Eldar Musayev wrote a useful blog posting back in June 2005 called "Really large messages with MSMQT and MSMQ (MSMQ/C) Adapter" which has some good points on memory capacity, etc. If you have any questions for Eldar then don't bother commenting this post as the whole blog has been retired (i.e. left available for reference but no longer being updated). Eldar has also changed product focus to Windows Home Server so will have already been brain-wiped of all Biztalk knowledge a while ago.