File RXDLLOS2.TXT                                Ch. d'H. Oct 26, 1992



Considerations when using DLLs with REXX in OS/2
================================================


REXX programs that use DLLs should run in separate processes
------------------------------------------------------------

A REXX program that uses one of the utility DLLs should execute
in a separate process. If the REXX program is started directly
from the OS/2 command line, it executes within the same process
as CMD.EXE, the OS/2 command interpreter. The command "CMD /c ..."
can be used to start a second copy of CMD.EXE that runs within
a separate process.

The following code sequence can be used to transparently start a
second CMD.EXE at the beginning of a REXX program that uses the
DLL:

   parse source os . mod_name
   select
      when os = "OS/2" then do
         "@echo off"
         parse arg mode main_parms
         if mode <> "INDIRECT" then do
            "cmd /c" mod_name "INDIRECT" arg(1); exit rc; end
         end
      otherwise parse arg main_parms
      end

The reason for this recommendation is, that the DLL remains
active during the live time of the process that accesses it.
Using a separate process to access the DLL guarantees that
the DLL is properly initialized before a DLL routine is called,
and properly terminated when the process ends. Otherwise, when
the REXX program is interrupted (e.g. by pressing CTL-BREAK or
because of a REXX syntax error) and started again within the
same process, the DLL would not be terminated and re-initialized.
Objects that have been opened by a previous REXX program and
have not been closed would still be open.
