midrange.com code scratchpad
Name:
ENTRY EXIT procedures using C++ Constructor / Destructor wrapper for RPG IV service programs
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
10/01/2022 12:31:18 am
IP:
Logged
Description:
Back in 2007, Bob Cozzi created a special C++ wrapper to allow service programs created in any ILE language to take advantage of the C++ runtime constructor and destructor capabilities. This in effect gives a *SRVPGM the equivalent of an *INZSR when first activated, and an exit routine when the *SRVPGM is deactivated (usually when the AG is destrpyed or at end-of-job.)
Code:
  1.      //  MODULE: ENTRYEXIT
  2.      //  Compile using CRTCPPMOD.
  3.      //  Bind to any *PGM or *SRVPGM
  4.      //  Copyright 2007 by Robert Cozzi, Jr.
  5.      //   All rights reserved.
  6.      //   No warranty is expressed or implied.
  7.  
  8.      //  There is no need to modify this code.
  9.      //   You must specify the module name on
  10.      //   the module parm of CRTSRVPGM, for example:
  11.      //     e.g CRTSRVPGM SRVPGM(x) MODULE(X  ENTRYEXIT)
  12.      //  In the RPG source code in any one of the
  13.      //  service program's modules, create a
  14.      //  subprocedure named RPG_ENTRY and RPG_EXIT.
  15.      //  Be sure to export both of them.
  16.  
  17.      //  Bob Cozzi's Entry/Exit Object for *SRVPGM's.
  18.     extern "C"  int RPG_ENTRY(void);
  19.     extern "C"  int RPG_EXIT(void);
  20.  
  21. class Entry_Exit
  22. {
  23. public:
  24.    int m_nEntry;
  25.    int m_nExit;
  26.  
  27. // Construction
  28. public:
  29.     Entry_Exit(void);   // standard constructor
  30.    ~Entry_Exit(void);
  31. };
  32.  
  33.   Entry_Exit::Entry_Exit(void) {
  34.         m_nEntry = RPG_ENTRY();
  35.   }
  36.  
  37.   Entry_Exit::~Entry_Exit() {
  38.         m_nExit = RPG_EXIT();
  39.   }
  40.  
  41.   static  Entry_Exit  My_Entry_Exit;
  42.  
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css