Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:pluginexpire [2015/09/14] (current)
Line 1: Line 1:
 +====== Making a Plug-in That Expires ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates an easy way to make a plug-in expire.//
  
 +===== Question =====
 +I would like to release a work-in-progress,​ or WIP, version of my plug-in so I can get some customer feedback before shipping. I would like the plug-in to expire after a number of days. Is there something in Rhino that could help with this?
 +
 +===== Answer =====
 +Rhino does not have any feature that can help with this. But, it is not too difficult to compare the compile date of the plug-in with the current date to see if you plug-in should load or not. The following example code demonstrates this.
 +
 +<code c++>
 +BOOL CTestPlugIn::​OnLoadPlugIn()
 +{
 +#if defined(WIP)
 +
 +  // Easy cheezy way of testing to see if plug-in has expired.
 +  COleDateTime compile_time;​
 +  compile_time.ParseDateTime( ON_wString(__DATE__"​ "​__TIME__),​ 0, 0x0409 );
 +
 +  COleDateTime current_time( COleDateTime::​GetCurrentTime() );
 +
 +  COleDateTimeSpan span = current_time - compile_time;​
 +  int elapsed_days = span.GetDays();​
 +
 +  const int warn_after_days = 30;   // or whatever...
 +  const int expire_after_days = 40; // or whatever...
 +
 +  if( elapsed_days >= warn_after_days )
 +  {
 +    HWND hWnd = RhinoApp().MainWnd();​
 +    if( elapsed_days >= expire_after_days )
 +    {
 +      ON_wString str = L"This WIP has expired. Please download the latest and greatest...";​
 +      ::​MessageBox( hWnd, str, PlugInName(),​ MB_OK | MB_ICONERROR );
 +      return -1; // This will cause the plug-in not to load and not display an Rhino error.
 +    }
 +    else
 +    {
 +      ON_wString str;
 +      str.Format( L"This WIP will expire in %d days. Please download the latest and greatest...",​ expire_after_days - elapsed_days ); 
 +      ::​MessageBox( hWnd, str, PlugInName(),​ MB_OK | MB_ICONEXCLAMATION );
 +    }
 +  }
 +#endif
 +
 +  // If we got here, then the WIP was good. 
 +  // So, do other plug-in initialization
 +  // and return TRUE to run.
 +
 +  return TRUE;
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/pluginexpire.txt ยท Last modified: 2015/09/14 (external edit)