TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Henk den Adel
from: Peter Fitzsimmons
date: 1995-06-26 17:20:06
subject: Using Info-Zip in Programs.

PF> All I did was rename main() to lh2main(),  and 
 PF> put the code in a dll --so
 PF> you set up an 'int argc, char *argv[]' and call it,  and it returns
 PF> success/failure.

 HdA> Is this procedure a general feature? 

No,  but it was pretty easy to do.

 HdA> Suppose I have the source code of a program which 
 HdA> converts file A to B via:

 HdA> do_it a.out b.psc

 HdA> If i rename main(int argc, char *argv[]) into tric_main(etc) and 
 HdA> compile it into a DE_MIJNE.DLL, is this program 
 HdA> available to other programs just by calling: 
 HdA> tric_main(2, myargs) or do I miss some vital point?

You got it -- there are a few issues though:

        1) The dll should be trusted code (if it traps,  it will
           bring down the whole process).

        2) The dll must clean up after itself;  if shouldn't leave any
           files open or memory allocated (IBM Cset++ comes with a nice
           feature to catch the latter).

        3) If the dll was originally a PM program,  it will only work
           from a pm process.

        4) If the dll was a text mode program (printf,  not vio),  it
           will work form any type of pgm,  but its output will end up
           in the bit bucket if used by a PM program that does not
           redirect stdin/stdout.

           If you are running it from a text mode program (that has
           threads still running),  and you want your own output sent to
           the screen and the dll's output sent somewhere else, you have
           a dilemma.

           I solved this problem with lh2.dll by mucking around with the
           CRT's copy of stdout.   Note this is NOT redirecting stdout
           for the whole process (just the DLL's CRT copy of stdout):

           static FILE save;
           FILE *fstd = NULL;
           int pascal lhSetStdout(char *fname, char *mode)
           {
               fstd = fopen(fname, mode);
               if(fstd){
                   save = *stdout;
                   *stdout = *fstd;
                   return TRUE;
               }
               else
                   return FALSE;
           }

           int pascal lhResetStdout(void)
           {
               if(fstd){
                   fclose(stdout);
                   *stdout = save;
                   fstd = NULL;
                   return TRUE;
               }
               return FALSE;
           }

--- Maximus/2 2.02p1
* Origin: Sol 3/Toronto (905)858-8488 (1:259/414)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/99 3615/50 396/1 270/101 105/103 42 712/515 711/808
@PATH: 711/809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.