You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, June 27th 2012, 6:49pm

QLibrary fails to call method over remote

Hello QT-Programmers,
i'm programming a plugin architecture for my application, so that it can also be expanded "dynamically".
For this I use the QLibrary to "reload/read" the dlls, form the plugin, dynamically and get access remotely to the functions.

Here's some code

Source code

1
2
3
4
5
6
7
8
9
10
11
#ifndef IPLUGIN_H
#define IPLUGIN_H

class PluginInterface
{
public:
    virtual void process() = 0;
    virtual const char* getName() = 0;
};

#endif // IPLUGIN_H


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "plugin1.h"
#include <iostream>
Plugin1::Plugin1()
{
}

void Plugin1::process()
{
 std::cout << "Remote call to "<< getName() << " successful!!!" << std::endl;
}

const char* Plugin1::getName()
{
  return "Plugin1";
}

extern "C" PLUGIN1SHARED_EXPORT Plugin1* CreatePlugin()
{
  return new Plugin1();
}

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typedef PluginInterface* (*PLUGIN_FACTORY);
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QLibrary lib("./Plugin1");
    PLUGIN_FACTORY p = (PLUGIN_FACTORY) lib.resolve("CreatePlugin");
    if(p)
    {
        //yes, this DLL exposes the 2 functions we >need, it is a plugin we can use!
        //now invoke the factory to create the plugin object
        PluginInterface* p_plugin = (*p);
	std::cout << "Now working with plugin: " << p_plugin->getName() << std::endl;
        p_plugin->process();
    }else
    {
        std::cout << "Plugin NOT WORKING!!!!" << std::endl;
    }
    return a.exec();
}


The plugin is loaded correctly, but when i start the program i'm getting the following error message, which cames on line #13 if i call p_plugin->getName()

Does maybe someone has some advice for me because I'm just as wrong? If you are now saying, have a look you'll get a"read access violation"...thx...i can read that too! But how i get that????
Or there is this another random approach based, as I dont no've noticed?

Thanks in advance
Mariob1

PS: Maybe you have even just tried to implement a plugin architecture, and it's a lot easier ... or have example code ... I'll take any advic...thx

This post has been edited 3 times, last edit by "mariob1" (Jun 27th 2012, 7:11pm)


2

Wednesday, June 27th 2012, 9:34pm

what is the value of p_plugin?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Thursday, June 28th 2012, 12:52pm

hello Amleto,

the value of p_plugin is 0x161e9.

if you want I can send you the whole program so that you can also debug it

4

Thursday, June 28th 2012, 7:20pm

yeah, maybe that is best to put the project here.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.