Creating and compiling a basic Palm program that uses WebSphere MQ messaging

Note:
SupportPac EAP1 includes an example application and its source code. You can use this program instead of a user written program. Please refer to Using the SupportPac EAP1 example project file and code.

To create your own program, use the following procedure:

  1. Start Metrowerks CodeWarrior
  2. Create a new project using the File menu.
  3. Select one of the following, depending on your system:
    1. CodeWarrior Version 5
      1. From the dialog box prompting you to 'Select Project Stationary', expand the + next to 'Palm OS' and click Palm OS C App.
      2. Click OK.
      3. In the dialog box that is displayed, select an appropriate directory for the project folder and give the project a name, such as 'BasicApp'.
      4. Click OK.
    2. CodeWarrior Version 6
      1. From the tabbed dialog box, click Palm OS 3.1 (English) Stationary.
      2. In the text field on the right, give the project a name, such as 'BasicApp' and set the location text field to the directory in which you want to store your project.
      3. Click OK.
      4. In the dialog box that is displayed, click Palm OS C App.
      5. Click OK.
    3. CodeWarrior Version 7
      1. From the tabbed dialog box, click Palm OS 3.5 Stationary.
      2. In the text field on the right, give the project a name, such as "BasicApp" and and set the location text field to the directory in which you want to store your project.
      3. Click OK.
      4. In the dialog box that is displayed, click Palm OS C App.
      5. Click OK.
    4. CodeWarrior Version 8
      Note:
      You cannot use the CodeWarrior Version 8 Demo to build a WebSphere MQ Everyplace because you will have link errors.
      1. From the project tab in the Newdialog box, click Palm OS Application Stationary.
      2. In the text field on the right, give the project a name, such as "BasicApp" and set the location text field to the directory in which you want to store your project.
      3. Click OK.
      4. In the dialog box that is displayed, click Palm OS C App.
      5. Click OK.

    This creates a new folder and a set of source files within that folder. The folder has the same name as the project, and the project file within the folder has the extension name, .mcp, for example "BasicApp.mcp".

  4. In CodeWarrior, a project window called "ExtensionName.mcp ("BasicApp" for example ) opens. Expand the Source and Resource folders to display the Starter.c and Starter.rsrc files.

    Double-click the Starter.c file to open an edit window.

  5. Edit the Starter.c file as shown in the following example (adding the text in italics).
    #include <Pilot.h>
    #include <SysEvtMgr.h>
    #include "StarterRsc.h"
    #include <hmq.h>         
    /* <- MQe header file */ 
    static Err AppStart(void)
    {
        StarterPreferenceType prefs;
        Word prefsSize;
     
        /******* MQe defines ************/
        MQEHSESS   hSess;
        MQEHFIELDS hMsg;
        MQEINT32   compcode;
        MQEINT32   reason;
        MQEPMO     pmo = MQEPMO_DEFAULT; 
    		/* Set default put message options */
        
        /******* End of MQe defines *****/
     
        // Read the saved preferences / saved-state information.
        prefsSize = sizeof(StarterPreferenceType);
        if (PrefGetAppPreferences(appFileCreator, 
    											appPrefID, , , true) 
    											!= noPreferenceFound)
           	{
           	}
     
        /*************** MQe code added ***************/
       
        /* Initialize the session: connect to the local queue manager */
        hSess = MQeInitialize("MyAppsName", 
    											&compcode, 
    											&reason);
     
        /* Allocate memory for the MQeMsgObject 
    			(an MQeFields object with two set fields) */
        hMsg = MQeFieldsAlloc( hSess, 
    											MQE_OBJECT_TYPE_MQE_MSGOBJECT, 
    											&compcode, 
    											&reason);
     
        /* If the allocation was successful put some data 
    			into the MQeFields object */
        if ( compcode == MQECC_OK ) {
            /* Put ASCII text "Hello World" into the MQeMsgObject */
            /*in a field named "HelloAscii" */
            MQeFieldsPut(hSess, hMsg, 
    									"HelloAscii", 
    									MQE_TYPE_ASCII, 
                        	"Hello World", 
    									StrLen("Hello World"), 
    									&compcode, 
    									&reason );
        }
     
        /* Now put the message to a Queue Manager and Queue */
        MQeQMgrPutMsg( hSess, 
    							"aQMgrName", 
    							"aQueueName", 
    							&pmo, 
    							hMsg, 
    							&compcode,  
    							&reason);
        /* If the  initial allocation was successful, */ 
        /* free the memory held by the MQeMsgObject */
        if (hMsg!=MQEHANDLE_NULL) {
            MQeFieldsFree(hSess, 
    									hMsg, 
    									&compcode, 
    									&reason );
        }
        /* Terminate the session */
        MQeTerminate(hSess, 
    							&compcode, 
    							&reason); 
     
        /*************** End of MQe code **************/
    	
        return 0;
    }
    

    This code:

    1. Starts a session to the local queue manager
    2. Creates an MQeFields message object
    3. Puts some data into the message object
    4. Puts the message to a queue manager and queue with the names aQMgrName and aQueueName. Change these names to those of the queue manager and queue that you want to use. If the queue manager and queue are on a separate WebSphere MQ Everyplace server, the queue manager name is ExampleQM and the queue name is SYSTEM.DEFAULT.LOCAL.QUEUE.
    5. Frees the message object and terminates the session when the message put is complete.

    When you have finished editing the Starter.c file, save it and close the edit window.

  6. Link the WebSphere MQ Everyplace stub library as follows:
    1. Select the project window
    2. Click Project -- > Add Files. This opens the Select files to add... dialog.
    3. Change the Files of type filter to Library files and navigate to the hmq.lib file. If you kept the directory structure of this SupportPac after installation, hmq.lib is in the MQeNativeClient/Palm OS Support directory.
    4. Select hmq.lib and click Add-- > OK. CodeWarrior should then automatically add a path entry that points to where the hmq.lib has been installed, that is the "User Paths" list in the "Target" group of "Starter Settings".

    A project message appears confirming that an access path has been added.

  7. Ensure that the compiler knows where to find the WebSphere MQ Everyplace header file hmq.h as follows:
    1. Do one of the following to display the Starter Settings dialog:
      • From the Edit menu, select Starter-Debug Settings.
      • In the project window, select Starter-Debugfrom the drop-down menu and click theStarter-Debug Settings icon.
    2. In the Target group on the left of the dialog box, click Access Paths.
    3. Click the System Paths radio button and click Add. This opens the Browse for Folder dialog box.
    4. Navigate to the folder where hmq.h is stored and click OK to add the path to hmq.h to the System Path.
    5. In the Starter-Debug Settings dialog, click OK.
  8. Do one of the following to compile the program:

    The project builds a compiled program called Starter.prc and stores it in the project folder.



© IBM Corporation 2002. All Rights Reserved