home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / bin / p205.zip / exesrc / p_dll.c < prev    next >
C/C++ Source or Header  |  1994-12-18  |  2KB  |  71 lines

  1. /*****************************************************************************/
  2. /*           Copyright (c) 1994 by Jyrki Salmi <jytasa@jyu.fi>             */
  3. /*        You may modify, recompile and distribute this file freely.         */
  4. /*****************************************************************************/
  5.  
  6. /*
  7.    Routines that load P.DLL and get the address of p_tranfer() entry
  8.    function.
  9. */
  10.  
  11. #include <stdio.h>
  12. #define INCL_DOSMODULEMGR
  13. #define INCL_DOSPROCESS
  14. #include <os2.h>
  15. #include "typedefs.h"
  16. #include "common.h"
  17. #include "p.h"
  18. #include "p_dll.h"
  19. #include "error.h"
  20. #include "modules.h"
  21.  
  22. static HMODULE dll_handle;
  23. U32 (* _System p_transfer)(P_CFG *) = NULL;
  24.  
  25. char *get_exe_path(void) {
  26.  
  27.   PTIB tib;
  28.   PPIB pib;
  29.  
  30.   DosGetInfoBlocks(&tib, &pib);    /* rc is always 0, no need to check */
  31.   return(pib->pib_pchcmd);
  32. }
  33.  
  34. void load_p_dll(void) {
  35.  
  36.   APIRET rc;
  37.   U8 *exe_path;
  38.   U8 path[256];
  39.  
  40.   rc = DosLoadModule(NULL, 0L, "P", &dll_handle);
  41.   if (rc) {
  42.     /* P.DLL was not found in directory specified with LIBPATH, let's look */
  43.     /* up for it from the directory where P.EXE was ran from. */
  44.     exe_path = get_exe_path();
  45.     sprintf(path, "%.*sP.DLL", (int)get_dir_len(exe_path), exe_path);
  46.     rc = DosLoadModule(NULL, 0L, path, &dll_handle);
  47.     if (rc)
  48.       os2_error(P_ERROR_DOSLOADMODULE, rc, MODULE_P_DLL, __LINE__, path);
  49.   }
  50.   /* Query the address of p_transfer() entry function */
  51.   rc = DosQueryProcAddr(dll_handle,
  52.             0,
  53.             "p_transfer",
  54.             (PFN *)&p_transfer);
  55.   if (rc)
  56.     os2_error(P_ERROR_DOSQUERYPROCADDR, rc,
  57.         MODULE_P_DLL, __LINE__,
  58.         "p_transfer");
  59. }
  60.  
  61. void unload_p_dll(void) {
  62.  
  63.   APIRET rc;
  64.  
  65.   rc = DosFreeModule(dll_handle);
  66.   if (rc)
  67.     os2_error(P_ERROR_DOSFREEMODULE, rc,
  68.         MODULE_P_DLL, __LINE__,
  69.         "P");
  70. }
  71.