home *** CD-ROM | disk | FTP | other *** search
- /* ============================================================================
-
- Tutorial sample plugin for CustomBar
- Copyright (C) 2004 Lizardsoft
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Lizardsoft can be contacted below through the following means:
-
- E-mail : software@lizardsoft.com
- Website: lizardsoft.com
-
- Post : Lizardsoft
- P.O. Box 37002
- 1005 Ottawa St. N
- Kitchener, Ontario
- N2A 2H0
- Canada
-
- ============================================================================ */
-
- // The extern "C" __declspec(dllexport) declaration is tediously long, so define it
- // as something shorter. The extern "C" part makes sure that the plugin functions get
- // compiled using C naming convention when using a C++ compiler. The __declspec(dllexport)
- // causes the function to be exported in the DLL.
-
- #define TUTORIAL_API extern "C" __declspec(dllexport)
-
-
- // include Windows header files
- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
- #include <windows.h>
-
- // include SDK header files
- #include "..\..\CBPluginLib.h"
-
- // IMPORTANT LINKING NOTE: you must link the SDK libraries DataLib.lib and CBPluginLib.lib
- // for linking to be successful. Depending on your compiler, you may
- // also need to link in some additional windows libraries.
-
- // amount of functions that this plugin has
- #define FUNCAMOUNT 2
-
- // declare all exported functions
- // see close to top of file for TUTORIAL_API definition
- TUTORIAL_API int GetPluginInfo( PLUGIN_INFO *Info );
- TUTORIAL_API int Initialize();
- TUTORIAL_API int Deinitialize();
-
- TUTORIAL_API int HelloWorld( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved );
- TUTORIAL_API int PrintChar( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved );
-
- // declare a few global variables
-
- // plugin information needs to be available throughout
- PLUGIN_FUNC FuncInfo[FUNCAMOUNT];
-
-
- // Entry function for DLL. Generally it is compiler generated. Most plugins do not need to
- // do anything other than make sure it exists and returns TRUE.
- BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
-
-
- // CustomBar calls this function for you when the plugin is loaded. In order to make sure
- // that your plugin works correctly in future versions of CustomBar, you should perform
- // any initialization here instead of DllMain. Must return 1 to indicate successful plugin
- // load. Must exist even if empty.
-
- int Initialize()
- {
- return 1;
- }
-
-
- // CustomBar calls this function right before the plugin is unloaded. Do your deinitialization
- // here. Must return 1 to indicate successful plugin unload. Must exist even if empty.
-
- int Deinitialize()
- {
- return 1;
- }
-
-
- // CustomBar calls this function after loading the plugin to obtain information about the
- // plugin. Note that CB doesn't copy the plugin information into its own memory space.
- // This means that the strings pointed to in the PLUGIN_INFO structure MUST remain valid
- // until the plugin is unloaded.
-
- int GetPluginInfo( PLUGIN_INFO *Info )
- {
- // change the information below to your info
- // if something like
- Info->Name = "My First Plugin";
- Info->ObjectName = "Tutorial"; // this is the name that CB sees for the plugin
- Info->Author = "Lizardsoft";
- Info->Email = "software@lizardsoft.com";
- Info->Version = "v1.0";
- Info->Copyright = "Copyright (C) 2002-2004, Lizardsoft All Rights Reserved";
-
- // FuncInfo is a global array, see near top of file for its definition
- Info->FuncInfo = FuncInfo;
- Info->FuncAmt = 2;
-
- Info->FuncInfo[0].SetInfo( "HelloWorld", "", 0, 0 );
- Info->FuncInfo[1].SetInfo( "PrintChar", "sis", 2, 0 );
-
- return 1;
- }
-
-
- // The Tutorial.HelloWorld plugin function. Takes no parameters and returns nothing.
-
- int HelloWorld( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved )
- {
- // display a simple Hello message box
- MessageBox( 0, "Hello World", "Greetings", MB_OK );
-
- // always return 1
- return 1;
- }
-
-
- // Second sample function - Tutorial.PrintChar. Takes a string and an integer as parameters
- // and returns a string. Read the tutorial for more information on how this function works.
-
- int PrintChar( P_UNIVAL *Params, P_UNIVAL *Result, PLUGIN_CALLINFO *CallInfo, void *Reserved )
- {
- const char *CharStr = Params[0].GetConstStr(); // grab parameter 1
- int Count = Params[1].GetInt(); // grab parameter 2
- char Chr;
- char *NewStr;
- int i;
-
- // grab the first character
- Chr = CharStr[0];
-
- // allocate some memory for the string
- NewStr = new char[Count+1];
-
- // repeat that character Count times
- for( i=0; i<Count; i++ )
- NewStr[i] = Chr;
-
- // string needs null terminator, i at this point i is already set to 1 past the
- // last character in string
- NewStr[i] = '\0';
-
- // since we tell CustomBar that we return a string, we MUST set the Result to a string
- // value
- Result->SetStr(NewStr);
-
- // don't forget to free allocated memory!
- delete[] NewStr;
-
- // always return 1
- return 1;
- }