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;