Annotation of os2sdk/demos/examples/dynlink/dynlink2.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * dynlink2.c
                      3:  *
1.1.1.2 ! root        4:  *     Created by Microsoft Corp. 1987
1.1       root        5:  *
                      6:  * This example illustrates the use of run time dynamic linking.
                      7:  * A call to the procedure PRINTDATA is made in the dynamic link library DYNLIB.
                      8:  *
                      9:  * NB - The DYNLIB.DLL file must be located in the LIBPATH specified in your
                     10:  *     config.sys.  You can place your current directory at the beginning
                     11:  *     of the LIBPATH by saying libpath=.;c:\; etc.
1.1.1.2 ! root       12:  *
1.1       root       13:  */
                     14: 
1.1.1.2 ! root       15: #define INCL_DOSMODULEMGR
        !            16: #define INCL_DOSPROCESS
        !            17: 
        !            18: #include <os2def.h>
1.1       root       19: #include <stdio.h>
1.1.1.2 ! root       20: #include <bsedos.h>
1.1       root       21: 
                     22: #define        MODULE          "DYNLIB"        /* Name of dynamic link module */
                     23: #define PROCNAME       "PRINTDATA"     /* Name of routine in dynamic module */
                     24: #define FBSZ           32              /* size of failure buffer */
                     25: 
                     26: main(argc, argv)
                     27:        int     argc;
                     28:        char    *argv[];
                     29: {
1.1.1.2 ! root       30:        HMODULE         ModHdl;                 /* dynamic link module handle */
1.1       root       31:        unsigned        rc;                     /* return code */
                     32:        char            fbuf[FBSZ];             /* failure obj name buffer */
                     33:        void            (far pascal * DynamicProc)();
                     34: 
                     35: 
                     36:        /* Load dynamic link module */
                     37: 
1.1.1.2 ! root       38:        if (rc = DosLoadModule( fbuf, FBSZ, MODULE, &ModHdl))
1.1       root       39:        {
                     40:                printf("module %s not found, failing obj %s error: %d\n",
                     41:                        MODULE, fbuf, rc);
1.1.1.2 ! root       42:                DosExit(EXIT_PROCESS,1);   /* exit with error */
1.1       root       43:        }
                     44:        
                     45:        /* Get the address of procedure PROCNAME in the dynamic link module */
                     46: 
1.1.1.2 ! root       47:        if (rc = DosGetProcAddr( ModHdl, PROCNAME,
        !            48:                                 (PFN far *) &DynamicProc))
1.1       root       49:        {
                     50:                printf("procedure %s not found, error: %d\n", PROCNAME, rc);
1.1.1.2 ! root       51:                DosExit(EXIT_PROCESS,1);   /* exit with error */
1.1       root       52:        }
                     53: 
                     54:        while(1)
                     55:        {
                     56:                (*DynamicProc)();   /* display shared and non-shared data   */
1.1.1.2 ! root       57:                DosSleep(100L);     /* yield the processor                */
1.1       root       58:        }
                     59: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.