Created
November 3, 2014 03:19
-
-
Save hamsham/5584a86fdb0a48425501 to your computer and use it in GitHub Desktop.
An example API for an example plugin system in C++.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Plugin API header | |
*/ | |
#ifndef __PLUGIN_API_H__ | |
#define __PLUGIN_API_H__ | |
/* | |
* Windows-specific settings for a dynamic library | |
*/ | |
#ifdef _WIN32 | |
/* Standard dynamic library extension */ | |
#ifndef PLUGIN_EXT | |
#define PLUGIN_EXT ".dll" | |
#endif | |
/* Calling convention for functions loaded at runtime. */ | |
#ifndef PLUGIN_CALL | |
#define PLUGIN_CALL __stdcall | |
#endif | |
/* Determine if the plugin will be imported at runtime or exported to a library. */ | |
#ifdef BUILD_PLUGIN | |
#define PLUGIN_API __declspec(dllexport) | |
#else | |
#define PLUGIN_API __declspec(dllimport) | |
#endif | |
/* | |
* Dynamic library settings for Linux and OSX | |
*/ | |
#else | |
/* Standard dynamic library extension */ | |
#ifndef PLUGIN_EXT | |
#define PLUGIN_EXT ".so" | |
#endif | |
/* Calling convention for functions loaded at runtime. */ | |
#ifndef PLUGIN_CALL | |
#define PLUGIN_CALL __cdecl | |
#endif | |
/* Determine if the plugin will be imported at runtime or exported to a library. */ | |
#ifndef PLUGIN_API | |
#define PLUGIN_API | |
#endif | |
#endif | |
class PLUGIN_API plugin { | |
public: | |
virtual ~plugin() = 0; | |
virtual void printMessage() const = 0; | |
}; | |
inline plugin::~plugin() { | |
// An inline destructor will avoid requiring a .cpp file in each | |
// user-created library. | |
} | |
extern "C" plugin* PLUGIN_API PLUGIN_CALL createPluginInstance(); | |
typedef plugin* (*pluginFactory_t)(); | |
extern "C" void PLUGIN_API PLUGIN_CALL destroyPluginInstance(plugin* const pPlugin); | |
typedef void (*pluginDeleter_t)(plugin* const); | |
#ifndef PLUGIN_FACTORY_NAME | |
#define PLUGIN_FACTORY_NAME "createPluginInstance" | |
#endif | |
#ifndef PLUGIN_DELETER_NAME | |
#define PLUGIN_DELETER_NAME "destroyPluginInstance" | |
#endif | |
#endif /* __PLUGIN_API_H__ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment