home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / loaddll.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  63 lines

  1. /***
  2. *loaddll.c - load or free a Dynamic Link Library
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _loaddll() and _unloaddll() - load and unload DLL
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <oscalls.h>
  13. #include <stdlib.h>
  14. #include <process.h>
  15.  
  16. /***
  17. *int _loaddll(filename) - Load a dll
  18. *
  19. *Purpose:
  20. *       Load a DLL into memory
  21. *
  22. *Entry:
  23. *       char *filename - file to load
  24. *
  25. *Exit:
  26. *       returns a unique DLL (module) handle if succeeds
  27. *       returns 0 if fails
  28. *
  29. *Exceptions:
  30. *
  31. *******************************************************************************/
  32.  
  33. int __cdecl _loaddll(char * szName)
  34. {
  35.     return ((int)LoadLibrary(szName));
  36. }
  37.  
  38. /***
  39. *int _unloaddll(handle) - Unload a dll
  40. *
  41. *Purpose:
  42. *       Unloads a DLL. The resources of the DLL will be freed if no other
  43. *       processes are using it.
  44. *
  45. *Entry:
  46. *       int handle - handle from _loaddll
  47. *
  48. *Exit:
  49. *       returns 0 if succeeds
  50. *       returns DOS error if fails
  51. *
  52. *Exceptions:
  53. *
  54. *******************************************************************************/
  55.  
  56. int __cdecl _unloaddll(int hMod)
  57. {
  58.     if (!FreeLibrary((HANDLE)hMod)) {
  59.         return ((int)GetLastError());
  60.     }
  61.     return (0);
  62. }
  63.