Created
February 22, 2014 14:30
-
-
Save carasuca/9155687 to your computer and use it in GitHub Desktop.
Plugin publishing - dynamic linking and loading
This file contains hidden or 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
// now in your plugin.cpp | |
#include <Resources.h> | |
#define PLUGIN_API __declspec(dllexport) | |
PLUGIN_PARAMS( | |
L"param1", | |
L"param2", | |
L"param3", | |
L"param4", | |
) | |
#include <ResourceEx.h> | |
PLUGIN_NAMED_PARAMS( | |
L"name", L"value", // or embraced :) | |
{L"name2", L"value2"} | |
); |
This file contains hidden or 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
// to publish supported plugin strings | |
// use a single dllexport | |
// then just LoadLibrary and GetProcAddress in your framework | |
// defined in the framework.h | |
#define PLUGIN_PARAMS(...) PLUGIN_API const wchar_t* const * plugin_params(size_t& count) \ | |
{ \ | |
static const wchar_t* const params[] = \ | |
{ __VA_ARGS__}; \ | |
count = sizeof(params)/sizeof(wchar_t*); \ | |
return params; \ | |
} | |
// SIMPLIFIED VERSION - no count, just trailing NULL (unsafe) | |
// signature: PLUGIN_API const wchar_t* const * plugin_params() | |
// static const wchar_t* const params[] = {__VA_ARGS__, 0} | |
// or | |
// static const wchar_t* const params[] = {__VA_ARGS__ L"", 0} | |
// - trick to prevent empty PLUGIN_PARAMS() or missing trailing comma errors |
This file contains hidden or 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
// EXTENDED VERSION with structures | |
struct ParamDefinition // defines a single published parameter | |
{ | |
const wchar_t *name, *value; | |
}; | |
// Enumerated version | |
// in this case provide ParamEnum in your framework, | |
// so plugin authors can implement predefined stuff | |
enum ParamEnum : size_t {default_param, optional_param}; | |
struct ParamDefinition2 | |
{ | |
ParamEnum param_id; | |
const wchar_t* value; | |
}; | |
// of course there can also be a flag field in ParamDefinition | |
// describing additional information | |
#define PLUGIN_NAMED_PARAMS(...) PLUGINL_API const ParamDefinition* const plugin_named_params(size_t& count) \ | |
{ \ | |
static const ParamDefinition params[] = {__VA_ARGS__}; \ | |
count = sizeof(params)/sizeof(ParamDefinition); \ | |
return params; \ | |
} | |
// NOTE: | |
// you can use this mechanism to publish functions | |
typedef void (plugin_func_t*)(void); | |
struct FunctionDefinition | |
{ | |
const wchar_t* name; | |
plugin_func_t ptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment