MQSeries Application Wizard


Overview

When writing an MQSeries application for Windows NT, a common choice for a development language is C or C++.  When writing an application in those languages on Windows, a popular development tool is the Microsoft Visual Studio V6.0 product.  Visual Studio provides a Windows specific integrated development environment (IDE) in which applications can be edited, compiled and debugged.

When writing  an MQSeries application within the Visual Studio environment, each new application must be coded with common MQSeries calls and the location of the MQSeries include and library directories be added to the project paths.

These are common tasks which must be repeated over and over for each new application.

Visual Studio provides the capability for 3rd parties to develop enhancements to the IDE.  These enhancements are called Application Wizards and allow the user of Visual Studio to rapidly develop the skeleton of an application complete with include and library paths already specified.

The MQSeries Application Wizard

This document focuses on an implementation of an Application Wizard for Visual Studio V6.0 which provides for the rapid development of MQSeries based applications.

  The MQSeries Application Wizard is available as a ZIP file here.  This ZIP file contains two files:

Both these files should be extracted into the Visual Studio Common Template directory.  This directory is located at

<Root of Visual Studio Install>\Common\MSDev98\Template

For example:

C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Template

Using the Application Wizard

Once the MQSeries Application Wizard has been installed, start Visual Studio.  Once Visual Studio has been started, select the File and then New menu items.  A dialog will be presented from which the project tab should be selected.  This dialog shows the available project types which can be created.  A screenshot of the dialog is shown below:

MQSeries Appwizard selection

Within the panel, an MQSeries Application Wizard type can be selected.  To complete the panel, enter a name in the Project name entry field and press OK.

The following dialog will be presented.

From within this dialog, the selection of an application which performs an MQPUT or and MQGET can be made.  Make a selection and press Finish.

A confirmation dialog will be presented and then the project itself will be created.  The project will contain a C/C++ source file with either an MQGET or an MQPUT with all the necessary other functions such as MQCONN, MQOPEN and structure completion.  In addition to the skeleton source program, the created project will also be ready to be compiled having had the location of header files, library files and required libraries already added to the project configuration.

A sample skeleton source file generated by the application wizard is shown at the end of this document.

Feedback

Feedback on the application wizard for MQSeries is welcomed.  Based upon feedback, additional project settings or additional skeletons for common tasks may be added.

Please send any comments by Email to Neil Kolban at kolban@us.ibm.com

Disclaimer

This application wizard is supplied on an as-is basis.  No formal product level support is offered on this utility.


Sample Skeleton source file generated by the wizard

//
// myApp.cpp	-	MQ Application
//
#include <cmqc.h>							// MQ Header file
#include <stdio.h>							// IO header
#include <string.h>							// String functions

int main(int argc, char *argv[])
{
	MQHCONN		hConn;						// Connection handle
	MQHOBJ		hObject;					// Object handle
	MQCHAR48	qmgrName;					// Name of queue manager
	MQLONG		iCompCode;					// Completion code
	MQLONG		iReason;					// Reason code qualifying CompCode
	MQOD		mqod = {MQOD_DEFAULT};				// Object description
	MQMD		mqmd = {MQMD_DEFAULT};				// Message Descriptor
	MQPMO		mqpmo = {MQPMO_DEFAULT};			// Put message options
	MQLONG		iMessageLen;					// Messsage Length
	MQBYTE		buffer[1000];					// Message data buffer

	if (argc < 3)
	{
		printf("Usage: Program queueName queueManagerName\n");
		return(1);
	}

	strncpy(mqod.ObjectName, argv[1], MQ_Q_NAME_LENGTH);		// Name of the queue
	strncpy(qmgrName, argv[2], MQ_Q_MGR_NAME_LENGTH);		// Name of the queue manager
	strcpy(mqod.ObjectQMgrName, "");				// Use the connected QMgr

	// MQCONN
	MQCONN(qmgrName,						// Queue manager
		&hConn,							// Connection handle
		&iCompCode,						// Completion code
		&iReason);						// Reason code
	if (iCompCode == MQCC_FAILED)
	{
		printf("MQCONN failed with reason code %ld\n", iReason);
		return(iReason);
	}

	MQLONG iOpenOptions = MQOO_OUTPUT |				// Open queue for output
		MQOO_FAIL_IF_QUIESCING;					// but not if MQM stopping

	// MQOPEN
	MQOPEN(hConn,							// connection handle
		&mqod,							// object descriptor for queue
		iOpenOptions,						// open options
		&hObject,						// object handle
		&iCompCode,						// MQOPEN completion code
		&iReason);						// reason code
	if (iCompCode == MQCC_FAILED)
	{
		printf("MQOPEN failed with reason code %ld\n", iReason);
		return(iReason);
	}

	// MQPUT
	// TODO: Populate the message to be placed on the queue
	iMessageLen = 0;						// size of message data
	mqpmo.Options |= MQPMO_NEW_MSG_ID;				// generate a new MSGID
	MQPUT(hConn,							// connection handle
		hObject,						// object handle
		&mqmd,							// message descriptor
		&mqpmo,							// default options (datagram)
		iMessageLen,						// message length
		buffer,							// message buffer
		&iCompCode,						// completion code
		&iReason);						// reason code
	if (iCompCode == MQCC_FAILED)
	{
		printf("MQPUT failed with reason code %ld\n", iReason);
		return(iReason);
	}

	// MQCLOSE
	MQCLOSE(hConn, &hObject, MQCO_NONE, &iCompCode, &iReason);
	// MQDISC
	MQDISC(&hConn, &iCompCode, &iReason);
	return(0);
}


Last Updated: June 21, 1999