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

  1. /***
  2. *getproc.c - Get the address of a procedure in a DLL.
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _getdllprocadd() - gets a procedure address by name or
  8. *       ordinal
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <oscalls.h>
  14. #include <process.h>
  15.  
  16. /***
  17. *int (*)() _getdllprocaddr(handle, name, ordinal) - Get the address of a
  18. *       DLL procedure specified by name or ordinal
  19. *
  20. *Purpose:
  21. *
  22. *Entry:
  23. *       int handle - a DLL handle from _loaddll
  24. *       char * name - Name of the procedure, or NULL to get by ordinal
  25. *       int ordinal - Ordinal of the procedure, or -1 to get by name
  26. *
  27. *
  28. *Exit:
  29. *       returns a pointer to the procedure if found
  30. *       returns NULL if not found
  31. *
  32. *Exceptions:
  33. *
  34. *******************************************************************************/
  35.  
  36. int (__cdecl * __cdecl _getdllprocaddr(int hMod,
  37.                                              char * szProcName,
  38.                                              int iOrdinal))()
  39. {
  40.     typedef int (__cdecl * PFN)();
  41.  
  42.     if (szProcName == NULL) {
  43.         if (iOrdinal <= 65535) {
  44.             return ((PFN)GetProcAddress((HANDLE)hMod, (LPSTR)iOrdinal));
  45.         }
  46.     }
  47.     else {
  48.         if (iOrdinal == -1) {
  49.             return ((PFN)GetProcAddress((HANDLE)hMod, szProcName));
  50.         }
  51.     }
  52.  
  53.     return (NULL);
  54.  
  55. }
  56.