summaryrefslogtreecommitdiff
path: root/plugins/example/main.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2011-03-17 23:58:19 +0200
committerGluzskiy Alexandr <sss123next@list.ru>2011-03-17 23:58:19 +0200
commitf4a5bae0c010e3c20d6420c9de2bb74182b26b6e (patch)
treeac120eaa84821ac21fd51235829c1db82570d230 /plugins/example/main.cpp
parentb170dc2b10df0e66acc5bc0bb89ba2c68a755f12 (diff)
events are working )
Diffstat (limited to 'plugins/example/main.cpp')
-rw-r--r--plugins/example/main.cpp51
1 files changed, 47 insertions, 4 deletions
diff --git a/plugins/example/main.cpp b/plugins/example/main.cpp
index c556d47..00fde1e 100644
--- a/plugins/example/main.cpp
+++ b/plugins/example/main.cpp
@@ -18,19 +18,62 @@ extern PLUGININFO pluginInfo;
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[32];
- wxSnprintf(msg, 31, _T("Core version is %d."), core_version);
+ wxChar msg[64];
+ wxSnprintf(msg, 63, _T("Core version is %d."), core_version);
wxMessageBox(msg, _T("Info"), wxOK | wxICON_INFORMATION);
}
{
- wxChar msg [32];
- wxSnprintf(msg, 31, _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.
+ 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;