home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / DLLTEST.C < prev    next >
C/C++ Source or Header  |  1996-06-17  |  1KB  |  65 lines

  1. //
  2. //
  3. // A short and hopefully easy to understand demonstration of CauseWay DLL
  4. // usage with Watcom.
  5. //
  6. //
  7.  
  8.  
  9. // Need function definitions
  10. #include "dllfunc.h"
  11.  
  12.  
  13. // Name the module. DLLS for stack version and DLLR for register
  14. char ModuleName[]={"DLLR"};
  15.  
  16.  
  17. //
  18. //The actual do something code.
  19. //
  20. int main()
  21. {
  22. unsigned char *DLL;
  23. void _cdecl (*DLLFunction)(char *);
  24.  
  25.     // Try and load the module.
  26.     DLL=LoadModule(ModuleName);
  27.     if (DLL) {
  28.  
  29.         printf("Module ");
  30.         printf(ModuleName);
  31.         printf(" loaded sucessfully\n");
  32.  
  33.         // Fetch the test function address
  34.         DLLFunction=GetProcAddress(DLL,"_SAYHELLO");
  35.  
  36.         if (DLLFunction) {
  37.  
  38.             // Give the test function a shout
  39.             DLLFunction("Hello World!\n");
  40.  
  41.         } else {
  42.  
  43.             printf("Failed to GetProcAddress\n");
  44.  
  45.         }
  46.  
  47.             // Lose the module again
  48.             FreeModule(DLL);
  49.  
  50.             printf("Module ");
  51.             printf(ModuleName);
  52.             printf(" discarded\n");
  53.  
  54.     } else {
  55.  
  56.         printf("Failed to load ");
  57.         printf(ModuleName);
  58.         printf(" module...\n");
  59.  
  60.     }
  61.  
  62. return(0);
  63. }
  64.  
  65.