Re: Glib::Module



Hi I got it to work Only had to change the main.cpp to:

#include <iostream>
#include <glibmm/module.h>
#include "TestPluginApp_generic.h"
int main()
{
    GenericPlugin* (*CreatePlug)();
    Glib::Module plugin("plugins/sample.dll");
    if(!plugin)
        std::cout << "Error: " << plugin.get_last_error() << std::endl;
    else
    {
std::cout << "Name of the plugin: " << plugin.get_name() << std::endl;
        if(plugin.get_symbol("CreatePlug", (void*&)CreatePlug))
        {
        	GenericPlugin *loaded_plugin = CreatePlug();
std::cout << "Function action() returns: " << loaded_plugin->action() << std::endl;
        }
        else
            std::cout << "Error: " << plugin.get_last_error() << std::endl;
    }
	return 0;
}




Sourcecode:
//======================================================================//

////The App////

//main.cpp
#include <iostream>
#include <glibmm/module.h>
#include "TestPluginApp_generic.h"
int main()
{
   void *actionpl = 0;
   Glib::Module plugin("plugins/sample.dll");
   if(!plugin)
       std::cout << "Error: " << plugin.get_last_error() << std::endl;
   else
   {
std::cout << "Name of the plugin: " << plugin.get_name() << std::endl;
       if(plugin.get_symbol("action", actionpl))
           std::cout << "Function exist" << std::endl;
       else
           std::cout << "Error: " << plugin.get_last_error() << std::endl;
   }
   return 0;
}
////////////////////////////////////////////////////////////////////////////////
//TestPluginApp_generic.h
#ifndef TESTPLUGINAPP_GENERIC_H
#define TESTPLUGINAPP_GENERIC_H
#ifdef __cplusplus
extern "C" {
#endif

class GenericPlugin
{
   public:
       virtual int action() = 0;
};

// This is the plugin function each plugin overrides for the main app to
// create an instance of the plugin child class.
extern GenericPlugin * CreatePlug();
//----------------------------------------------------------------------------
typedef GenericPlugin * (*CREATEPLUG_PROC)();

#ifdef __cplusplus
}
#endif
#endif //TESTPLUGINAPP_GENERIC_H

//======================================================================//
////The  module compile it as sample.dll////
////put this module in a 'plugin/' folder of the test app////

//sampleplugin.h
#ifndef SAMPLEPLUGIN_H
#define SAMPLEPLUGIN_H

#include "../testpluginapp_generic.h"

class SamplePlugin : public GenericPlugin
{
   public:
       virtual int action();
};

#endif //SAMPLEPLUGIN_H
////////////////////////////////////////////////////////////////////////////////
//sampleplugin.cpp
#include "../testpluginapp_generic.h"
#include "sampleplugin.h"
#include <iostream>

int SamplePlugin::action()
{
   std::cout << "Hello from SamplePlugin!" << std::endl;
   return 0;
}

GenericPlugin * CreatePlug()
{
   return new SamplePlugin;
}

//======================================================================//




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]