PreviousNext
Help > Programming with LAUNCHER Office > Advanced programming > CL programs samples > CallExe
CallExe

 This example shows how to send and receive messages to and from the AS/400.

 

Description

When the message EXE is received, the server executes a program containing the dialog box shown below. LAUNCHER Office then just waits for an event sent by the application.

 

A click on the appropriate button and the message is sent to the AS/400 :

 

When the "Message to AS/400" button is clicked, the program uses the LNCMessage function found in the LNCMSG.DLL library, and thus allows messages to be sent to the AS/400.

Pressing the "Back to Terminal" button ends the program. The AS/400 then passes back into command mode, while the PC is placed in the 'waiting for connection' mode.

 

On AS/400 :

Parameters or command

= = = >Call callexec ‘194.206.160.97’

Message To send to the AS/400

Message send by CALLEXE program

 

Source of the CALLEXE program (Visual Basic source)

 

Declarations :

' LAUNCHER/400 functions from LNCMSG.DLL

' ----------------------------------

' Send a message to AS/400 and give hand to it

Declare Function LNCMessage Lib "lncmsg.dll" (ByVal nRetCode As Long, ByVal szRetString As String) As Long

' Receive a message from AS/400

Declare Function LNCRcvMessage Lib "lncmsg.dll" (piRetCode As Long, ByVal szRetString As String) As Long

' Set the reference to event we want to receive from AS/400

Declare Function LNCSetPostMessage Lib "lncmsg.dll" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

 

' Windows function

' -----------------

 

' Get the ID of a control in the form.

Declare Function GetDlgCtrlID Lib "user32" (ByVal hwnd As Long) As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

 

Global Const WM_COMMAND As Long = &H111

Global Const BN_CLICKED As Long = 0

 

Global Const RET_REJECT = 0

Global Const RET_ACKNOWLEDGE = 1

Global Const RET_MESSAGE = 2

 

On the Message To AS/400 button :

Dim ret As Long

Dim RetCode As Long

Dim RetString As String * 100

Dim DlgId As Integer

'LAUNCHER/400 will simulate a click on button 'Command3'

DlgId = GetDlgCtrlID(Command3.hwnd)

ret = LNCSetPostMessage(Form1.hwnd, WM_COMMAND, DlgId, Command3.hwnd)

'Send a message to the AS/400 application.

ret = LNCMessage(2, Text1.Text)

 

On the Back To Terminal button :

Dim ret As Long

 

'Tell to AS/400 that we stop to talk

ret = LNCMessage(2, "*END")

 

On the Command3 button (hidden) :

Dim ret As Long

Dim str As String * 200

 

' This button was clicked by LAUNCHER/400,

' when the AS/400 call the application for

' the 2nd time and more.

' We can receive a message from the AS/400

' application.

ret = LNCRcvMessage(ret, str)

Text1.Text = str

 

For the first execution, after clicking on the "Message to AS/400" button, LAUNCHER Office will simulate the "Click on the Command3 button" event. Then the application will be waiting for a callback message.

When the event is simulated, the application sends the Text1 control's text to the AS/400.

When the AS/400 calls the application the second time, the application will run from the Command3 code, and will retrieve the calling parameters furnished by the AS/400 to LAUNCHER.

 

Source of the CALLEXE program (CL language)

 

/* Variables used for opening the communication */

PGM         PARM(&SVRADDR)

DCL         VAR(&SVRADDR) TYPE(*CHAR) LEN(30)

DCL         VAR(&HANDLE) TYPE(*CHAR) LEN(50)

DCL         VAR(&CCSID) TYPE(*CHAR) LEN(10)

 

/* Variables used for sending the commands */

DCL         VAR(&CMD) TYPE(*CHAR) LEN(10)

DCL         VAR(&OPT) TYPE(*CHAR) LEN(1)

DCL         VAR(&PARM1) TYPE(*CHAR) LEN(512)

DCL         VAR(&PARM2) TYPE(*CHAR) LEN(1024)

DCL         VAR(&RESULT) TYPE(*CHAR) LEN(512)

DCL         VAR(&MSGID) TYPE(*CHAR) LEN(7)

DCL         VAR(&MSG1) TYPE(*CHAR) LEN(80)

DCL         VAR(&MSG2) TYPE(*CHAR) LEN(80)

 

/* Opening of only a single communication with the PC*/

CHGVAR      VAR(&HANDLE) VALUE('*ONLY')

 

/* Translates the CCSID depending on the job CCSID */

CHGVAR      VAR(&CCSID) VALUE('*JOB')

 

/* Connection to the PC */

CALL        PGM(LNCOPEN) PARM(&HANDLE &SVRADDR &CCSID)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

/* Save the active window on the PC */

CHGVAR      VAR(&CMD) VALUE('STO')

CHGVAR      VAR(&PARM1) VALUE(' ')

CHGVAR      VAR(&PARM2) VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

            &PARM2 &RESULT)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

/* Minimizes the active window(Emulation AS400) */

CHGVAR      VAR(&CMD)VALUE('MIN')

CHGVAR      VAR(&PARM1)VALUE(' ')

CHGVAR      VAR(&PARM2)VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

            &PARM2 &RESULT)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

/* Begin communication using the application CALLEXE.EXE, OPT=

/* Then the demon sends a message to the AS 400 following an   */

/* application event */

 

CALLIT:

CHGVAR      VAR(&CMD) VALUE('EXE')

CHGVAR      VAR(&OPT) VALUE('2')

CHGVAR      VAR(&PARM1) VALUE('%LNCDIR%\SAMPLES\CALLEXE.EXE')

CHGVAR      VAR(&PARM2) VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

            &PARM2 &RESULT)

 

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

SNDPGMMSG   MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA(&RESULT) TOPGMQ +

(*EXT) MSGTYPE(*STATUS)

IF          COND(%SST(&RESULT 1 4) =

GOTO        CMDLBL(CALLIT)

 

FINISH:

 

/* Minimize the active window (Application CALLEXE) */

CHGVAR      VAR(&CMD) VALUE('MIN')

CHGVAR      VAR(&PARM1) VALUE(' ')

CHGVAR      VAR(&PARM2) VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 &PARM2 &RESULT)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

/* Restore the saved window (Emulation AS/400)*/

CHGVAR      VAR(&CMD) VALUE('RCL')

CHGVAR      VAR(&OPT) VALUE('0')

CHGVAR      VAR(&PARM1) VALUE(' ')

CHGVAR      VAR(&PARM2) VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 &PARM2 &RESULT)

 

/* End of communication with the PC */

CLOSE:

CHGVAR      VAR(&CMD) VALUE('END ')

CHGVAR      VAR(&PARM1) VALUE(' ')

CHGVAR      VAR(&PARM2) VALUE(' ')

CALL        PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 &PARM2 &RESULT)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

CALL        PGM(LNCCLOSE) PARM(&HANDLE)

MONMSG      MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

GOTO END

 

ERROR:

CALL        PGM(LNCCLOSE) PARM(&HANDLE)

RCVMSG      MSG(&MSG1) SECLVL(&MSG2) MSGID(&MSGID)

SNDPGMMSG   MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA('Error !!!!! ' +

            *CAT &MSGID *CAT ' ' *CAT &MSG1 *CAT ' ' *CAT &MSG2)+

            MSGTYPE(*ESCAPE)

END:

ENDPGM

 

See also the EVENTTEST example in the AS/400 installation library, illustrating the exchange of synchronization messages between the PC and the AS/400.