home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 September / CHIP_CD_2004-09.iso / software / custombar / CustomBar_trial_100_setup.exe / Tutorial.cpp < prev    next >
C/C++ Source or Header  |  2004-06-30  |  6KB  |  180 lines

  1. /* ============================================================================
  2.  
  3. Tutorial sample plugin for CustomBar
  4. Copyright (C) 2004 Lizardsoft
  5.  
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10.  
  11. This library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. Lesser General Public License for more details.
  15.  
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20. Lizardsoft can be contacted below through the following means:
  21.  
  22. E-mail : software@lizardsoft.com
  23. Website: lizardsoft.com
  24.  
  25. Post   : Lizardsoft 
  26.          P.O. Box 37002
  27.          1005 Ottawa St. N
  28.          Kitchener, Ontario
  29.          N2A 2H0
  30.          Canada
  31.          
  32. ============================================================================ */
  33.  
  34. // The extern "C" __declspec(dllexport) declaration is tediously long, so define it
  35. // as something shorter. The extern "C" part makes sure that the plugin functions get
  36. // compiled using C naming convention when using a C++ compiler. The __declspec(dllexport)
  37. // causes the function to be exported in the DLL.
  38.  
  39. #define TUTORIAL_API extern "C" __declspec(dllexport)
  40.  
  41.  
  42. // include Windows header files
  43. #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
  44. #include <windows.h>
  45.  
  46. // include SDK header files
  47. #include "..\..\CBPluginLib.h"
  48.  
  49. // IMPORTANT LINKING NOTE: you must link the SDK libraries DataLib.lib and CBPluginLib.lib
  50. //                         for linking to be successful. Depending on your compiler, you may
  51. //                         also need to link in some additional windows libraries.
  52.  
  53. // amount of functions that this plugin has
  54. #define FUNCAMOUNT 2
  55.  
  56. // declare all exported functions
  57. // see close to top of file for TUTORIAL_API definition
  58. TUTORIAL_API int GetPluginInfo( PLUGIN_INFO *Info );
  59. TUTORIAL_API int Initialize();
  60. TUTORIAL_API int Deinitialize();
  61.  
  62. TUTORIAL_API int HelloWorld( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved );
  63. TUTORIAL_API int PrintChar( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved );
  64.  
  65. // declare a few global variables
  66.  
  67. // plugin information needs to be available throughout 
  68. PLUGIN_FUNC FuncInfo[FUNCAMOUNT];
  69.  
  70.  
  71. // Entry function for DLL. Generally it is compiler generated. Most plugins do not need to 
  72. // do anything other than make sure it exists and returns TRUE.
  73. BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
  74. {
  75.     switch (ul_reason_for_call)
  76.     {
  77.     case DLL_PROCESS_ATTACH:
  78.     case DLL_THREAD_ATTACH:
  79.     case DLL_THREAD_DETACH:
  80.     case DLL_PROCESS_DETACH:
  81.         break;
  82.     }
  83.     return TRUE;
  84. }
  85.  
  86.  
  87. // CustomBar calls this function for you when the plugin is loaded. In order to make sure 
  88. // that your plugin works correctly in future versions of CustomBar, you should perform 
  89. // any initialization here instead of DllMain. Must return 1 to indicate successful plugin 
  90. // load. Must exist even if empty.
  91.  
  92. int Initialize()
  93. {
  94.     return 1;
  95. }
  96.  
  97.  
  98. // CustomBar calls this function right before the plugin is unloaded. Do your deinitialization
  99. // here. Must return 1 to indicate successful plugin unload. Must exist even if empty.
  100.  
  101. int Deinitialize()
  102. {
  103.     return 1;
  104. }
  105.  
  106.  
  107. // CustomBar calls this function after loading the plugin to obtain information about the 
  108. // plugin. Note that CB doesn't copy the plugin information into its own memory space.
  109. // This means that the strings pointed to in the PLUGIN_INFO structure MUST remain valid
  110. // until the plugin is unloaded. 
  111.  
  112. int GetPluginInfo( PLUGIN_INFO *Info )
  113. {
  114.     // change the information below to your info
  115.     // if something like 
  116.     Info->Name       = "My First Plugin";
  117.     Info->ObjectName = "Tutorial";           // this is the name that CB sees for the plugin
  118.     Info->Author     = "Lizardsoft";
  119.     Info->Email      = "software@lizardsoft.com";
  120.     Info->Version    = "v1.0";
  121.     Info->Copyright  = "Copyright (C) 2002-2004, Lizardsoft All Rights Reserved";
  122.  
  123.     // FuncInfo is a global array, see near top of file for its definition
  124.     Info->FuncInfo   = FuncInfo;
  125.     Info->FuncAmt     = 2;
  126.  
  127.     Info->FuncInfo[0].SetInfo( "HelloWorld", "", 0, 0 );
  128.     Info->FuncInfo[1].SetInfo( "PrintChar", "sis", 2, 0 );
  129.  
  130.     return 1;
  131. }
  132.  
  133.  
  134. // The Tutorial.HelloWorld plugin function. Takes no parameters and returns nothing.
  135.  
  136. int HelloWorld( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved )
  137. {
  138.     // display a simple Hello message box
  139.     MessageBox( 0, "Hello World", "Greetings", MB_OK );
  140.  
  141.     // always return 1
  142.     return 1;
  143. }
  144.  
  145.  
  146. // Second sample function - Tutorial.PrintChar. Takes a string and an integer as parameters
  147. // and returns a string. Read the tutorial for more information on how this function works.
  148.  
  149. int PrintChar( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved )
  150. {
  151. const char *CharStr = Params[0].GetConstStr();   // grab parameter 1
  152. int           Count = Params[1].GetInt();        // grab parameter 2
  153. char Chr;
  154. char *NewStr;
  155. int i;
  156.  
  157.     // grab the first character
  158.     Chr = CharStr[0];
  159.  
  160.     // allocate some memory for the string
  161.     NewStr = new char[Count+1];
  162.  
  163.     // repeat that character Count times
  164.     for( i=0; i<Count; i++ )
  165.         NewStr[i] = Chr;
  166.  
  167.     // string needs null terminator, i at this point i is already set to 1 past the 
  168.     // last character in string 
  169.     NewStr[i] = '\0';
  170.  
  171.     // since we tell CustomBar that we return a string, we MUST set the Result to a string
  172.     // value
  173.     Result->SetStr(NewStr);
  174.  
  175.     // don't forget to free allocated memory!
  176.     delete[] NewStr;
  177.  
  178.     // always return 1
  179.     return 1;
  180. }