LCDInfo.com
http://forum.lcdinfo.com/

Starting new plugin
http://forum.lcdinfo.com/viewtopic.php?f=17&t=448
Page 1 of 1

Author:  Henri [ Tue Dec 09, 2003 0:13 ]
Post subject:  Starting new plugin

Here's some information for starting your own plugin with Visual C++. Information here is valid with a build 15 SDK.

First start new Win32 Dynamic-Link Library project. For project name you could use for example something_plugin. Then in the wizard select An empty DLL project.
Next create new C++ Source File in the project.

You need to export the getInterface function from the plugin. Easiest way to make it work is to copy the export.DEF file from some other plugin to the plugin directory and add the file in the project. If you're having problem of the plugin not loading your getInterface function might not be exported properly.

From Project->Settings->C/C++ tab->Code Generation category->Use run-time library select Debug Multithreaded DLL for debug build and Multithreaded DLL for release build.

You also need to have the SDK files somewhere so that they can be included in the plugin source.

Here's example code for a data plugin:
Code:
// GUID has to be different for every plugin as it is used to separate plugins from each other.
// Visual Studio includes a program called guidgen.exe to generate unique GUIDs.
// There are also other GUID generators available.
// GUID Format used here is the registry format.
#define PLUGINGUID "{10D593F7-5FA9-49e8-A77C-73C83140E6EE}"

#define PLUGINNAME "System information"
#define PLUGINDESCRIPTION "Longer description for System information if needed"
#define PLUGINVERSION "0.1 alpha"
#define PLUGINDATE "9.12.2003"
#define PLUGINAUTHOR "Someone"
#define PLUGINEMAIL "someone@somewhere.com"

// Name for the DataSource
#define DATANAME "SysInfo"

#include "..\sdk\component.h" // required
#include "..\sdk\plugin.h" // required
#include "..\sdk\data.h" // for DataSource
// #include "..\sdk\configure.h" // save and get setting values

#include "windows.h"
MEMORYSTATUS MemStatus;

// class derived from IPlugin is required for every plugin even if you don't use it yourself
class Plugin : public IPlugin
{
   virtual void __stdcall onCreate(void)
   {
      // do startup stuff here
   }

   virtual void __stdcall onDestroy(void)
   {
      // do things needed before destroying plugin

   }
};

// derive class from DataSource to make a data plugin
class Data : public DataSource
{
   virtual void __stdcall onCreate(void)
   {
      // add your own variables here
      addVar("SysInfo.TotalMemory",         "Total memory",      VAR_INT);
      addVar("SysInfo.AvailableMemory",      "Available memory", VAR_INT);
   }

   virtual void __stdcall onDestroy(void)
   {
   }

   virtual int __stdcall configure(void)
   {
      return -1;
   }

   virtual void __stdcall getValue(int varNo, Value value)
   {
      // depending of the plugin using switch may not work. like for unknown number of variables.
      // use your imagination ;)
      switch(varNo)
      {
         case 0:
         {
            GlobalMemoryStatus(&MemStatus);
            int tmp = MemStatus.dwTotalPhys/1024;
            value = tmp;
            break;
         }

         case 1:
         {
            GlobalMemoryStatus(&MemStatus);
            int tmp = MemStatus.dwAvailPhys/1024;
            value = tmp;
            break;
         }

      
      }
   }

private:

   
};

// IMPORTANT: without this your class won't be included in the plugin
// SYNTAX: RegisterFactory<Interface, YourDerivedClass> something;
static RegisterFactory<IPlugin, Plugin> plugin;
static RegisterFactory<IData, Data> data;

Author:  Henri [ Tue Dec 09, 2003 0:19 ]
Post subject:  Saving and reading settings

If you include the configure.h file from SDK you can save and read settings that are saved in windows registry.

#include "..\sdk\configure.h"

Code:
// saving settings
writeSettingInt("MYINTEGER", 3);
writeSettingFloat("MYFLOATINGPOINT", 3.45);
writeSettingString("MYSTRING", "characters here");

// reading settings
int a = readSettingInt("MYINTEGER");
double b = readSettingFloat("MYFLOATINGPOINT");

char c[256];
readSettingString("MYSTRING", c);

Author:  Starbuck3733T [ Wed Jun 16, 2004 17:12 ]
Post subject: 

Hey henri, any chance you've toyed around in .NET... or do you have a type library file for the exported interfaces? Thanks :)

Author:  Henri [ Wed Jun 16, 2004 20:23 ]
Post subject: 

No .NET for me yet. I think C++ compiler is needed to get working plugins done with the current SDK.
The plugin includes also some other files and functionality than just the interfaces.
But if you'd like to play with the C++ SDK then just mail me.

Author:  Henri [ Sat Oct 09, 2004 10:47 ]
Post subject: 

Example edited to work with build 18 SDK which means I added the configure() function to DataSource.

Page 1 of 1 All times are UTC + 2 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/