home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / DEXDLL.ZIP / DEXMAIN.C < prev    next >
C/C++ Source or Header  |  1996-04-16  |  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. // Need function definitions
  9. #include "dllfunc.h"
  10.  
  11. // Name the module
  12. char ModuleName[]={"DEXDLL"};
  13.  
  14. // main module value to be seen by the DLL
  15. int MainToDLLInt = 12345;
  16. char *MainToDLLCharStar="String in main module, visible by DLL";
  17.  
  18. //
  19. // The actual do something code.
  20. //
  21. int main()
  22. {
  23. unsigned char *DLL;
  24. void _cdecl (*DLLFunction)(char *);
  25.  
  26.     // Try and load the module.
  27.     DLL=LoadModule(ModuleName);
  28.     if (DLL) {
  29.  
  30.         printf("Module ");
  31.         printf(ModuleName);
  32.         printf(" loaded successfully\n");
  33.  
  34.         // Fetch the test function address
  35.         DLLFunction=GetProcAddress(DLL,"_SAYHELLO");
  36.  
  37.         if (DLLFunction) {
  38.             // Give the test function a shout
  39.             DLLFunction("Hello World!\n");
  40.  
  41.         } else {
  42.             printf("Failed to GetProcAddress\n");
  43.  
  44.         }
  45.             // Lose the module again
  46.             FreeModule(DLL);
  47.  
  48.             printf("Module ");
  49.             printf(ModuleName);
  50.             printf(" discarded\n");
  51.  
  52.     } else {
  53.         printf("Failed to load ");
  54.         printf(ModuleName);
  55.         printf(" module...\n");
  56.     }
  57.     return(0);
  58. }
  59.  
  60. void __export CalledByDLL (char * message)
  61. {
  62.     printf("I've been called by the DLL to say...\n");
  63.     printf(message);
  64. }
  65.