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:
- // MODULE: ENTRYEXIT
- // Compile using CRTCPPMOD.
- // Bind to any *PGM or *SRVPGM
- // Copyright 2007 by Robert Cozzi, Jr.
- // All rights reserved.
- // No warranty is expressed or implied.
-
- // There is no need to modify this code.
- // You must specify the module name on
- // the module parm of CRTSRVPGM, for example:
- // e.g CRTSRVPGM SRVPGM(x) MODULE(X ENTRYEXIT)
- // In the RPG source code in any one of the
- // service program's modules, create a
- // subprocedure named RPG_ENTRY and RPG_EXIT.
- // Be sure to export both of them.
-
- // Bob Cozzi's Entry/Exit Object for *SRVPGM's.
- extern "C" int RPG_ENTRY(void);
- extern "C" int RPG_EXIT(void);
-
- class Entry_Exit
- {
- public:
- int m_nEntry;
- int m_nExit;
-
- // Construction
- public:
- Entry_Exit(void); // standard constructor
- ~Entry_Exit(void);
- };
-
- Entry_Exit::Entry_Exit(void) {
- m_nEntry = RPG_ENTRY();
- }
-
- Entry_Exit::~Entry_Exit() {
- m_nExit = RPG_EXIT();
- }
-
- static Entry_Exit My_Entry_Exit;
-
|
|
|