LCDInfo.com

http://www.lcdinfo.com
It is currently Tue Nov 21, 2017 1:12

All times are UTC + 2 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Starting new plugin
PostPosted: Tue Dec 09, 2003 0:13 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
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;


Last edited by Henri on Sat Oct 09, 2004 10:47, edited 3 times in total.

Top
 Profile  
 
PostPosted: Tue Dec 09, 2003 0:19 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
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);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 17:12 
Offline

Joined: Wed Jan 28, 2004 22:48
Posts: 3
Location: Penn State
Hey henri, any chance you've toyed around in .NET... or do you have a type library file for the exported interfaces? Thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 20:23 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 09, 2004 10:47 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
Example edited to work with build 18 SDK which means I added the configure() function to DataSource.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 2 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group