Writing a Message Queuing COM Application using C++
2009-04-20 14:56
435 查看
The following list describes what is needed to start writing a sending or receiving application using COM components. Note that not all the possible tasks that can be implemented by your application are covered here. However, this topic does provide a basic understanding of what DLLs, objects, and methods are used to perform the tasks that most sending and receiving applications will need to perform.
Make sure that you know how Message Queuing is deployed. For example: are the queues you are sending messages to or reading messages from local or remote, is your application going to have access to the directory service at all times, is Message Queuing deployed across different enterprises, is Message Queuing deployed in a mixed mode environment.
To use smart pointers, Mqoa.dll must be imported to your application. All the C++ COM code examples provided by the Message Queuing SDK assume that the application imports this DLL using the #import directive and specifies the MSMQ namespace.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
Before using any smart pointer, your application must call CoInitialize or CoInitializeEx to initialize the COM library. After the COM library is no longer needed, your application must call CoUnitialize.
To create a queue, create a smart pointer to the MSMQQueueInfo interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
To send a message to a single destination queue, create smart pointers to the MSMQQueueInfo and MSMQMessage interfaces and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
To open a queue, create a smart pointer to the MSMQQueueInfo interface and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
To read a message from a queue, create smart pointers to the MSMQQueueInfo and MSMQMessage interfaces and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
Send comments about this topic to Microsoft.
Make sure that you know how Message Queuing is deployed. For example: are the queues you are sending messages to or reading messages from local or remote, is your application going to have access to the directory service at all times, is Message Queuing deployed across different enterprises, is Message Queuing deployed in a mixed mode environment.
To use smart pointers, Mqoa.dll must be imported to your application. All the C++ COM code examples provided by the Message Queuing SDK assume that the application imports this DLL using the #import directive and specifies the MSMQ namespace.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
#import "mqoa.dll" using namespace MSMQ;The #import directive generates two files that contain smart-pointer declarations for all Message Queuing objects: Mqoa.tlh and Mqoa.tli. The .tli file is included by an #include directive in the .tlh file, which is processed by the compiler as if it were named by an #include directive in your application. Do not include the Mqoai.h header file when you import Mqoa.dll.
Before using any smart pointer, your application must call CoInitialize or CoInitializeEx to initialize the COM library. After the COM library is no longer needed, your application must call CoUnitialize.
To create a queue, create a smart pointer to the MSMQQueueInfo interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo");For examples of creating queues, see C/C++ COM Code Example: Creating a Queue and C/C++ COM Code Example: Creating a Transactional Queue.
To send a message to a single destination queue, create smart pointers to the MSMQQueueInfo and MSMQMessage interfaces and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo"); // Destination queue IMSMQQueuePtr pQueue; // Instance of the opened queue. IMSMQMessagePtr pMsg("MSMQ.MSMQMessage"); // Message to be sentFor an example of sending a message to a specific queue, see C/C++ COM Code Example: Sending Messages to a Destination Queue.
To open a queue, create a smart pointer to the MSMQQueueInfo interface and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo"); // Destination queue IMSMQQueuePtr pQueue; // Instance of the opened queueFor an example of opening and closing a queue, see C++ COM Code Example: Opening a Queue.
To read a message from a queue, create smart pointers to the MSMQQueueInfo and MSMQMessage interfaces and declare a smart pointer to the MSMQQueue interface.
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
Copy Code
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo"); // Destination queue IMSMQQueuePtr pQueue; // Instance of the opened queue.For an example of synchronously reading message in a queue, see C/C++ COM Code Example: Reading Messages Synchronously.
IMSMQMessagePtr pMsg("MSMQ.MSMQMessage"); // Message to be read
Send comments about this topic to Microsoft.
相关文章推荐
- Using C++ Code in Android Application
- Calling C++ DLLs from C++ Application Using VS2020
- Writing multiboot PE kernels using Visual C++
- Using a Service Locator to Work with MessageBoxes in an MVVM Application
- Methods for Using Message Queuing Telemetry Transport for Sensor Networks to Support Sleeping Devices
- Using the Web Services and COM+ Event System in the .Net Application.
- Hybrid application using QML and Qt C++
- How to make a full-screen application using Symbian C++, 怎样在Sysmbian C++中制作全屏应用程序
- Calling C++ DLLs from C++ Application Using VS2020
- Writing BizTalk context properties to a message from a WCF service using behaviors
- C/C++代码覆盖工具http://magustest.com/blog/whiteboxtesting/using-gcov-lcov/
- COM+ Application Architecture Using Microsoft .Net
- Writing Web Services Client Applications using Visual C++
- C++ Tutorial - UI Application using visual studio 2012
- java restful风格服务报错:javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException
- Jersey&Rest异常:javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException
- Writing Asynchronous Web Application (Comet) using the Atmosphere Framework
- Write COM using only C++
- Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008
- A Beginner Tutorial for Writing Simple COM/ATL DLL and Using it with .NET