1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <wx/wx.h>
#include <wx/stdpaths.h>
#include <ec_pluginapi.h> //this is necessary, PLUGININFO structure, other related to load/unload plugin code
PLUGINLINK *pluginLink;
extern PLUGININFO pluginInfo;
#define CallService(service, param) pluginLink->CallService(service,param)
class wxPluginForEvilCore: public wxApp //this is like on default wxwidgets application
{
virtual bool OnInit();
};
IMPLEMENT_APP_NO_MAIN(wxPluginForEvilCore) //main() does not needed, we will create instance by hand later
const int EVENT_TEST = 666;
EVENT_HANDLER our_handler(void* data) //this is event handler fuction
{
return (void*(*)(void*))data; //just return data which we obtaned
}
bool wxPluginForEvilCore::OnInit()
{
wxMessageBox(_T("I am a plugin example") ,_T("Info"), wxOK | wxICON_INFORMATION);
int *core_version = (int*)CallService("EC/GetVersionInt", NULL); //using service implemented somewhere (in core, in plugins, in other place), NULL is data required for service
if(core_version)
{
wxChar msg[64];
wxSnprintf(msg, 63, _T("Core version is %d."), core_version);
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
{
wxChar msg [64];
wxSnprintf(msg, 63, _T("I have obtained special id %d from core"), pluginInfo.pluginid); //we must obtain special plugin id for calling services like raise event or so.
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
{ //trying to register event type
if(!pluginLink->RegisterEventType(EVENT_TEST, pluginInfo.pluginid))
{
wxChar msg[64];
wxSnprintf(msg, 63, _T("we have succesfuly registered event %d"), EVENT_TEST);
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
else
{
wxChar msg[64];
wxSnprintf(msg, 63, _T("we have failed to register event %d"), EVENT_TEST);
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
}
{//here we trying to handle our event type
if(!pluginLink->RegisterEventHandler(EVENT_TEST, (void* (*)(void*))our_handler))
{
wxChar msg[64];
wxSnprintf(msg, 63, _T("we have succesfuly registered event handler"));
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
else
{
wxChar msg[64];
wxSnprintf(msg, 63, _T("we have failed to register event handler"));
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
}
{ // raising our event
char* string = (char*)pluginLink->ExecuteEvent(EVENT_TEST, pluginInfo.pluginid, (void*)"this is custom data for test");
wxChar msg[128];
wchar_t* str = (wchar_t*)CallService("EC/toUtf16", (void*)string); //and amother example of core service usage
wxSnprintf(msg, 127, _T("we have obtained string \"%s\" in custom data"), str);
free(str); //should be freed
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
return true;
}
#ifdef _WIN32
HINSTANCE hInst;
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) //default dll entry point
{
hInst = hinstDLL;
return TRUE;
} //windows specific, does not needed ?
#endif
PLUGININFO pluginInfo =
{
// sizeof(PLUGININFO), //size of structure
(wchar_t*)L"example plugin", //name
0, //description
0, //author
0, //author email
0x0001010d //version 0.1.1.13
};
#ifdef _WIN32
extern "C" __declspec(dllexport) PLUGININFO* set_plugin_info()
#else
extern "C" PLUGININFO* set_plugin_info()
#endif
{
return &pluginInfo; //necessary, our plugin info for core can recognize us
}
#ifdef _WIN32
extern "C" __declspec(dllexport) int load(PLUGINLINK *link) //basic initialisation, registering new functions, do other basic initialisation, you can create infinite loop, or other code which use many time here, only fast basic initialisation
#else
extern "C" int load(PLUGINLINK *link)
#endif
{
pluginLink = link; //necessary
//some basic initialisation code
return 0; //all ok, retrun 0
}
#ifdef _WIN32
extern "C" __declspec(dllexport) int on_modules_loaded() //load main code from here, all services from other plugins must be avaible here
#else
extern "C" int on_modules_loaded() //load main code from here, all services from other plugins must be avaible here
#endif
{
wxApp::SetInstance(new wxPluginForEvilCore()); //create instance, i think here is right place, not in load where we do only basic initialisation
#ifdef _WIN32
wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW);
#else
int i = 1;
char **params = (char**)malloc(2);
params[0] = (char*)malloc(2);
strcpy(params[0], "");
wxEntry(i, params);
free(params[0]);
free(params);
#endif
return 0;
}
#ifdef _WIN32
extern "C" __declspec(dllexport) int unload()
#else
extern "C" int unload()
#endif
{
//do some cleanup on exit
wxEntryCleanup(); //call it before, or after other cleanup
return 0;
}
|