ILE C/C++ Programmer's Guide

Example: Using an ILE Bindable API to Display a DSM Session

The following example shows you how to call a Dynamic Screen Manager (DSM) ILE bindable API to display a DSM session. This DSM session echoes back data that you enter during the DSM session.

Instructions

  1. To create module T1520API using the source shown in Figure 103, enter:

    CRTCMOD MODULE(MYLIB/T1520API) SRCFILE(QCPPLE/QACSRC) OUTPUT(*PRINT)
  2. To create program T1520API, enter:

    CRTPGM PGM(MYLIB/T1520API) MODULE(MYLIB/T1520API) BNDDIR(QSNAPI)

    The CRTPGM command creates the program T1520API in library MYLIB.

  3. To run the program T1520API, enter:

    CALL PGM(MYLIB/T1520API)

    The output is as follows:

    +--------------------------------------------------------------------------------+
    |                  AS for iSeries 400 Programming Development Manager (PDM)      |
    | .................................................                              |
    | :  > abc                                        :                              |
    | :  > def                                        :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :                                               :                              |
    | :  ===>                                         :                              |
    | :  Echo lines until:   PF3 - exit               :                              |
    | :                                               :                              |
    | :...............................................:                              |
    |Selection or command                                                            |
    |===> call pgm(mylib/t1520api)                                                   |
    |F3=Exit       F4=Prompt       F9=Retreive        F10=Command entry              |
    |F12=Cancel    F18=Change Defaults                                               |
    +--------------------------------------------------------------------------------+

Code Samples

Figure 103. T1520API -- ILE C Source to Call an ILE C Procedure




/* This program uses Dynamic Screen Manager API calls to */
/* create a window and echo whatever is entered. This is an */
/* example of bound API calls. Note the use of #pragma argument */
/* in the <qsnsess.h> header file. OS, nowiden ensures that a pointer */
/* to an unwidened copy of the argument is passed to the API. */
/* */
/* Use BNDDIR(QSNAPI) on the CRTPGM command to build this */
/* example. */
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "QSYSINC/H/QSNAPI" 
 
/* QSNSESS nests QSNWIN and QSNLL include files. To get these 3 */
/* include files, do the following: */
/* 1) If you do not have a SRCPF called H in your Library (MYLIB), */
/* create one. */
/* 2) Copy QUSRTOOL/QATTSYSC/OPSN3API to MYLIB/H/QSNSESS */
/* 3) Copy QUSRTOOL/QATTSYSC/OPSN2API to MYLIB/H/QSNWIN */
/* 4) Copy QUSRTOOL/QATTSYSC/OPSN1API to MYLIB/H/QSNLL */
 
#define BOTLINE " Echo lines until: PF3 - exit"
 
/* DSM Session Descriptor Structure. */
 
typedef struct{
Qsn_Ssn_Desc_T sess_desc;
char buffer[300];
}storage_t;
 
void F3Exit(const Qsn_Ssn_T *Ssn, const Qsn_Inp_Buf_T *Buf, char *action)
{
*action = '1';
}
 


int main(void)
{
 
int i;
storage_t storage;

/* Declarators for declaring windows. Types are from the <qsnsess.h> */
/* header file. */
 
Qsn_Inp_Buf_T input_buffer = 0;
Q_Bin4 input_buffer_size = 50;
char char_buffer[100];
Q_Bin4 char_buffer_size;
 
Qsn_Ssn_T session1;
Qsn_Ssn_Desc_T *sess_desc = (Qsn_Ssn_Desc_T *) &storage;
Qsn_Win_Desc_T win_desc;
Q_Bin4 win_desc_length = sizeof(Qsn_Win_Desc_T);
char *botline = BOTLINE;
Q_Bin4 botline_len = sizeof(BOTLINE) - 1;
Q_Bin4 sess_desc_length = sizeof(Qsn_Ssn_Desc_T) +
botline_len;
Q_Bin4 bytes_read;
 
/* Initialize Session Descriptor API. */
 
QsnInzSsnD( sess_desc, sess_desc_length, NULL);

/* Initialize Window Descriptor API. */
 
QsnInzWinD( &win_desc, win_desc_length, NULL);
 
sess_desc->cmd_key_desc_line_1_offset = sizeof(Qsn_Ssn_Desc_T);
sess_desc->cmd_key_desc_line_1_len = botline_len;
memcpy( storage.buffer, botline, botline_len );
 
sess_desc->cmd_key_desc_line_2_offset = sizeof(Qsn_Ssn_Desc_T) +
botline_len;

/* Set up the session type. */
 
sess_desc->EBCDIC_dsp_cc = '1';
sess_desc->scl_line_dsp = '1';
sess_desc->num_input_line_rows = 1;
sess_desc->wrap = '1';


 
/* Set up the window size. */
 
win_desc.top_row = 3;
win_desc.left_col = 3;
win_desc.num_rows = 13;
win_desc.num_cols = 45;
 
/* Create a window session. */
 
sess_desc->cmd_key_action[2] = F3Exit;
session1 = QsnCrtSsn( sess_desc, sess_desc_length,
NULL, 0,
'1',
&win_desc, win_desc_length,
NULL, 0,
NULL, NULL);
if(input_buffer == 0)
{
input_buffer = QsnCrtInpBuf(100, 50, 0, NULL, NULL);
}
for (;;)
{
 
/* Echo lines until F3 is pressed. */
 
QsnReadSsnDta(session1, input_buffer, NULL, NULL);
if (QsnRtvReadAID(input_buffer, NULL, NULL) == QSN_F3)
{
break;
}
}
}

Notes:

  1. The prototypes for the DSM APIs are in the <qsnsess.h> header file.

  2. The #pragma argument (API, OS, nowiden) directive is specified for each API. This ensures that any value argument is passed by value indirectly.


[ Top of Page | Previous Page | Next Page | Table of Contents ]