home *** CD-ROM | disk | FTP | other *** search
/ Chip Hitware 7 A / CHIP_HITWARE_7A.iso / biuro / WordWrite / _SETUP.1 / aimdll.cpp < prev    next >
C/C++ Source or Header  |  1999-01-27  |  5KB  |  148 lines

  1. //----------------------------------------------------------------------------
  2. //  AdSoftware System
  3. //  Aureate Media Corporation
  4. //  Copyright ⌐ 1997-1999. All Rights Reserved.
  5. //
  6. //  FILE:         aimdll.cpp
  7. //  AUTHOR:       Mike Olson
  8. //
  9. //  OVERVIEW
  10. //  ~~~~~~~~
  11. //  C++ class to load and control the Aureate Media Advertising DLL
  12. //
  13. //----------------------------------------------------------------------------
  14.  
  15. #include "aimdll.h"
  16.  
  17. AimDll::AimDll(long int id, HWND hw, short int ad_size, unsigned long options)
  18. {
  19.   // Initialize data members
  20.   lastError = 0;
  21.  
  22.   // Load the DLL
  23.   hLib = LoadLibrary("advert.dll");
  24.  
  25.   // Locate and bind each function
  26.   dllStartup = (bool(__cdecl*)(dll_data*, HINSTANCE, HWND, long program_id, short ad_size, unsigned long options)) GetProcAddress(hLib, "_Startup");
  27.   dllPaint = (bool(__cdecl*)(dll_data*, HDC, int, int)) GetProcAddress(hLib, "_Paint");
  28.   dllOnClick = (bool(__cdecl*)(dll_data*)) GetProcAddress(hLib, "_OnClick");
  29.   dllSetCallback = (bool(__cdecl*)(dll_data*, DllCallbackFunc, void* p)) GetProcAddress(hLib, "_SetCallback");
  30.   dllSetAdRecordedCallback = (bool(__cdecl*)(dll_data*, DllCallbackFunc, void* p)) GetProcAddress(hLib, "_SetAdRecordedCallback");
  31.   dllSetNetworkCallback = (bool(__cdecl*)(dll_data*, DllCallbackFunc, void* p)) GetProcAddress(hLib, "_SetNetworkCallback");
  32.   dllSetBandwidthThrottle =    (bool (__cdecl*)(dll_data*, long)) GetProcAddress(hLib, "_SetBandwidthThrottle");
  33.   dllSetMinimumAdDisplayTime = (bool (__cdecl*)(dll_data *data, long seconds)) GetProcAddress(hLib, "_SetMinimumAdDisplayTime");
  34.   dllIsConnectOkay = (bool (__cdecl*)(dll_data *data, int *okay)) GetProcAddress(hLib, "_IsConnectOkay");
  35.   dllRetryConnect = (bool (__cdecl*)(dll_data *data)) GetProcAddress(hLib, "_RetryConnect");
  36.   dllSetNetworkState = (bool (__cdecl*)(dll_data *data, bool isNetUp)) GetProcAddress(hLib, "_SetNetworkState");
  37.   dllSetProxy = (bool(__cdecl*)(dll_data*, const char* server, long port, const char* additional)) GetProcAddress(hLib, "_SetProxy");
  38.   dllGetStatus = (bool (__cdecl*)(dll_data *data, unsigned long* status, bool clear)) GetProcAddress(hLib, "_GetStatus");
  39.   dllUseDefaultAd = (bool (__cdecl*)(dll_data *data, const char* image_file, const char* url_file)) GetProcAddress(hLib, "_UseDefaultAd");
  40.   dllShutdown = (bool(__cdecl*)(dll_data*)) GetProcAddress(hLib, "_Shutdown");
  41.   dllDebugTriggerEvent = (bool(__cdecl*)(dll_data *data, int num)) GetProcAddress(hLib, "_debugTriggerEvent");
  42.  
  43.   // Check to see that the DLL loaded properly and all functions were bound
  44.   if ((dllStartup == NULL) || (dllPaint == NULL) || (dllShutdown == NULL) ||
  45.       (dllOnClick == NULL) || (dllSetCallback == NULL) ||
  46.       (dllSetAdRecordedCallback == NULL) || (dllSetNetworkCallback == NULL) ||
  47.       (dllSetBandwidthThrottle == NULL) || (dllSetMinimumAdDisplayTime == NULL) ||
  48.       (dllIsConnectOkay == NULL) || (dllRetryConnect == NULL ) ||
  49.       (dllSetNetworkState == NULL ) || (dllSetProxy == NULL ) ||
  50.       (dllGetStatus == NULL ) || (dllUseDefaultAd == NULL ) ||
  51.       (dllDebugTriggerEvent == NULL)) {
  52.     FreeLibrary(hLib);
  53.     good = false;
  54.     lastError = ADE_DLL_LOAD_FAILURE;
  55.   } else {                // DLL loaded properly, initialize by calling startup
  56.     data = new dll_data;            // create private data member
  57.     data->last_error = &lastError;    // set error variable address
  58.     good = dllStartup(data, hLib, hw, id, ad_size, options); // initialize the DLL
  59.   }
  60. }
  61.  
  62. AimDll::~AimDll()
  63. {
  64.   if (good) {
  65.     dllShutdown(data);
  66.     FreeLibrary(hLib);
  67.     delete data;
  68.   }
  69. }
  70.  
  71. bool AimDll::Paint(HDC dc, int X, int Y)
  72. {
  73.   return (good ? dllPaint(data, dc, X, Y) : false);
  74. }
  75.  
  76. bool AimDll::OnClick(void)
  77. {
  78.   return (good ? dllOnClick(data) : false);
  79. }
  80.  
  81. bool AimDll::SetCallback(DllCallbackFunc f, void* p)
  82. {
  83.   return (good ? dllSetCallback(data, f, p) : false);
  84. }
  85.  
  86. bool AimDll::SetAdRecordedCallback(DllCallbackFunc f, void* p)
  87. {
  88.   return (good ? dllSetAdRecordedCallback(data, f, p) : false);
  89. }
  90.  
  91. bool AimDll::SetNetworkCallback(DllCallbackFunc f, void* p)
  92. {
  93.   return (good ? dllSetNetworkCallback(data, f, p) : false);
  94. }
  95.  
  96. bool AimDll::SetBandwidthThrottle(long BytesPerSec)
  97. {
  98.   return (good ? dllSetBandwidthThrottle(data, BytesPerSec) : false);
  99. }
  100.  
  101. bool AimDll::SetMinimumAdDisplayTime(long seconds)
  102. {
  103.   return (good ? dllSetMinimumAdDisplayTime(data, seconds) : false);
  104. }
  105.  
  106. bool AimDll::IsConnectOkay(bool& okay)
  107. {
  108.   if (good) {
  109.     int g = 0;
  110.     bool ret = dllIsConnectOkay(data, &g);
  111.     okay = (bool)g;
  112.     return ret;
  113.   } else {
  114.     return false;
  115.   }
  116. }
  117.  
  118. bool AimDll::RetryConnect(void)
  119. {
  120.   return (good ? dllRetryConnect(data) : false);
  121. }
  122.  
  123. bool AimDll::SetNetworkState(bool isNetUp)
  124. {
  125.   return (good ? dllSetNetworkState(data, isNetUp) : false);
  126. }
  127.  
  128. bool AimDll::SetProxy(const char* server, long port, const char* additional)
  129. {
  130.   return (good ? dllSetProxy(data, server, port, additional) : false);
  131. }
  132.  
  133. bool AimDll::GetStatus(unsigned long& status, bool clear)
  134. {
  135.   return (good ? dllGetStatus(data, &status, clear) : false);
  136. }
  137.  
  138. bool AimDll::UseDefaultAd(const char* image_file, const char* url_file)
  139. {
  140.   return (good ? dllUseDefaultAd(data, image_file, url_file) : false);
  141. }
  142.  
  143. bool AimDll::debugTriggerEvent(int num)
  144. {
  145.   return (good ? dllDebugTriggerEvent(data, num) : false);
  146. }
  147.  
  148.