home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBdisp / HTBDisp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  1.7 KB  |  91 lines

  1. // HTBDisp
  2.  
  3. // example for direct access to exported functions from HTBWin.exe and htbwrun.exe
  4.  
  5.  
  6. #include <windows.h>
  7.  
  8.  
  9. typedef void ( * lpDisp)(char *);
  10. typedef void ( * lphBasicWindow)();
  11.  
  12. lpDisp fpDisp = NULL;
  13. lphBasicWindow fphBasicWindow = NULL;
  14.  
  15. HINSTANCE hHTBWin;
  16.  
  17.  
  18. extern "C" 
  19. {
  20.  
  21. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  22.  
  23. // Function name    : InitHTB
  24. // Description        : initalize function pointer for disp function exported from htbwin.exe
  25. // Return type        : BOOL 
  26. BOOL InitHTB()
  27. {    BOOL result = TRUE;
  28.  
  29.     hHTBWin = LoadLibrary("HTBwin.exe");
  30.  
  31.     if (hHTBWin != NULL)
  32.     {    fphBasicWindow = (lphBasicWindow)GetProcAddress(hHTBWin,"g_hBasicWindow");
  33.  
  34.         if (fphBasicWindow == NULL)
  35.         {    FreeLibrary(hHTBWin);
  36.             result = FALSE;
  37.         }
  38.     }
  39.     else
  40.     {    result = FALSE;
  41.     }
  42.  
  43.     if (result == FALSE)
  44.     {    hHTBWin = LoadLibrary("HTBwrun.exe");
  45.  
  46.         if (hHTBWin != NULL)
  47.         {    fphBasicWindow = (lphBasicWindow)GetProcAddress(hHTBWin,"g_hBasicWindow");
  48.  
  49.             if (fphBasicWindow == NULL)
  50.             {    FreeLibrary(hHTBWin);
  51.                 result = FALSE;
  52.             }
  53.             else
  54.             {    result = TRUE;
  55.             }
  56.         }
  57.     }
  58.     
  59.     if (result == TRUE)
  60.     {    fpDisp = (lpDisp)GetProcAddress(hHTBWin,"Disp");
  61.  
  62.         if (fpDisp == NULL)
  63.         {    result = FALSE;
  64.         }
  65.     }
  66.  
  67.     return(result);
  68. }
  69.  
  70.  
  71. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. // Function name    : Disp
  74. // Description        : exported function that calls back into htbasic's exported disp function
  75. // Return type        : void 
  76. // Argument         : char * msg
  77. void Dlldisp(char * msg)
  78. {    if (fpDisp == NULL)
  79.     {    BOOL result = InitHTB();
  80.  
  81.         if (!result)
  82.         {    return;
  83.         }
  84.     }
  85.  
  86.     fpDisp(msg);
  87. }
  88.  
  89.  
  90.  
  91. } // end extern "C"