Hi buddies,
I have a project that I need to be plugin based. I have never done that before and I have intermediate C++ knowledge. I have googled and found a lot of links including this one. It is helpful and I don't know if I understand well.

Here is what I want to start with, Create application that does math (i.e simple calculator). The application does formatting and printing and the plugins does the actual math. the first thing I need is for someone to correct me if I'm wrong in my thinking below:

1. I have to create Abstaract plug in interface class IPlugin with methods:
getPluginName, loadPlugin unloadPlugin and the dataProcessor. This will be implemented by each plugin.

2. create class in the host IHost that checks the plugins if are valid and loads them with methods getPluginList, loadPluginsMethods, cleanPluginOnExit. this will only be implemented by the host.

am i right?
I will start coding once I get it right. Thanks

Member Avatar for ZootAllures

Hi,

You seem to have the right idea. I have used very similar architectures to the one you referred to (here), and they do work well. I don't think you need an IHost class in the host application unless the plugins need to call back into the host.

On the other hand, if there are only a handful of functions (such as load, unload, and process), then it would be simpler to simply export the functions from the plugin(s) and call them directly from the host application.

If you're expecting the complexity and number of functions to grow to the point where simple exports become unwieldy then certainly use the abstract interfaces. The biggest advantage you get from using interface classes is that you have a common definition (that is, a contract) between the host and the plugins and it's a lot easier to avoid mismatches between your functions.

I would start with the complete example given in the article (as I did myself several years ago) and build it up from there.

Some rules of building these interfaces are:
1. The concrete class must be instantiated (constructed) where it is implemented (ie, it is implemented in the plugin, you must instantiate it there).
2. All methods in the abstract interface must be pure virtual functions. No data, no non-pure functions.
3. The only part of the host code that the plugins need to see is the header containing the interface class(es).
4. The plugins could also call back into host code by implementing a similar kind of interface which is implemented in the host and called by the plugin.

I could probably find code examples, but I think the article has everything you require. Besides, I'm here if you need more.

Let me start some codes and I will be back
Thanks for reply

I have just started coding and I'm confused here. I have IPlugin.h which is the interface class. I'm stumbled at what loadPlugin returns. In my understanding it should return instance of plugin object that host will use. am I write? Here is where I have just started and stumbled...at very beginning

class IPlugin {
public:
	virtual const char* getName() = const 0;
        virtual whatToReturnHere loadPlugin( whatelseToPutHere something) = const 0;//I don't know how to formulate the method here!

};

Thanks

And I forgot one thing. Iam using ubuntu lucid box not the usual Vista :)

Member Avatar for ZootAllures

Sorry for the slow reply, I'm not in here a lot. In case you're still stuck:

The IPlugin class doesn't need a loadPlugin function. Put it in a header file, like this:

class IPlugin
{
public:
   virtual const char* Get_Name () const = 0;  // This is just an example.
   virtual void ProcessData () = 0;
};

Before anything can happen, the host has to get a real instance of the IPlugin interface from the plugin. To do this, export a function from your plugin like this:

extern "C" IPlugin* Create_Plugin ()
{
    return new Plugin;
}

So what's this "Plugin" class? It's an implementation of the IPlugin class. IPlugin is abstract (it's just a definition and has no code).

class Plugin : public IPlugin 
{
    virtual const char* Get_Name () const
    {
       return "TestPluginTheFirst";
    }
    virtual void ProcessData()
    {
       // Do some amazing plugin thing.
    }
};

So now, in your main program you can get your interface class instance just like the example at abstraction.com:

typedef IPlugin* (*PLUGIN_FACTORY)();
...
   PLUGIN_FACTORY factory = (PLUGIN_FACTORY)::GetProcAddress (h_mod, "Create_Plugin"); 

   if (factory != NULL)
   {
      // Call the function in the plugin to get the real interface class.
      IPlugin* plug = (*factory) ();

      // Now you have the interface in "plug" you can call any function
      // that you care to write in it.
      printf ("Now working with plugin: %s\n", plug->Get_Name ());

      plug->Process_Data ();
...

All the other code you need can be found at the original link you gave.

I did something and I'm stucked with some error

error: expected constructor, destructor, or type conversion before '(' token

BTW as I'm struggling, I have attached what concept I have on head. Just download and see. I have included Codelite Workspace for the whole App and plugin.
I'm still trying to get the concept in my head before I do anything that is anything.

Anyone can check and correct

Member Avatar for ZootAllures

In which file and line number are you getting the error?

See the whole error below.
I think I'm doing something wrong in extern "C" place

#ifdef MAKING_DLL
#define PLUGIN_EXPORTABLE __dllspec(dllexport)
#endif


//..............some code between here which I guess is fine
extern "C" {
	PLUGIN_EXPORTABLE IPlugin* loadPlugin(){
		return new Addition();
	}
	
	PLUGIN_EXPORTABLE void unloadPlugin(IPlugin* pluginInstance){
		delete pluginInstance;
	}
}

----------Build Started--------
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "PluginX_wsp.mk""
----------Building project:[ addition - Debug ]----------
mingw32-make.exe[1]: Entering directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition'
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp" -g -DMAKING_DLL=1 -o ./Debug/Addition.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.h:4,
from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces/IPlugin.h:26:19: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:38: error: expected constructor, destructor, or type conversion before '(' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:42: error: expected constructor, destructor, or type conversion before '(' token
mingw32-make.exe[1]: *** [Debug/Addition.o] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition'
----------Build Ended----------
2 errors, 1 warnings

Also I don't understand what the warning below means

warning: no newline at end of file

It should be __declspec , so ..

#define PLUGIN_EXPORTABLE __declspec(dllexport)

>> Also I don't understand what the warning below means
>> warning: no newline at end of file

You need to add a new-line character at the end of the file.
If you don't, your C++ program has undefined behaviour (believe it or not) ;)

It should be __declspec , so ..

#define PLUGIN_EXPORTABLE __declspec(dllexport)

What a stupid typo! Thanks a lot!
It made me stucked for loong

>> Also I don't understand what the warning below means
>> warning: no newline at end of file

You need to add a new-line character at the end of the file.
If you don't, your C++ program has undefined behaviour (believe it or not) ;)

Do you mean at end of each file I should put \n?

Now it throws errors that it cannot create object.
I'm checking what is wrong but if you can spot the error easily then help me with it

----------Build Started--------
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "PluginX_wsp.mk""
----------Building project:[ addition - Debug ]----------
mingw32-make.exe[1]: Entering directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition'
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp" -g -DMAKING_DLL=1 -o ./Debug/Addition.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.h:4,
from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces/IPlugin.h:26:19: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp: In function `IPlugin* loadPlugin()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:39: error: cannot allocate an object of type `Addition'
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition/Addition.cpp:39: error: because the following virtual functions are abstract:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces/IPlugin.h:7: error: virtual const char* IPlugin::getName() const
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces/IPlugin.h:8: error: virtual const char* IPlugin::getSign() const
mingw32-make.exe[1]: *** [Debug/Addition.o] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/addition'
----------Build Ended----------
4 errors, 1 warnings

I have checked this complain
because the following virtual functions are abstract:
It is true that they are abstract (virtual) but I have implemented them!
Let Me check if there is any method I haven't override

EDIT:
I have overridden all functions and lo, there is that error.
What is wrong?

>> Addition.cpp:39: error: because the following virtual functions are abstract:
>> IPlugin.h:7: error: virtual const char* IPlugin::getName() const
>> IPlugin.h:8: error: virtual const char* IPlugin::getSign() const

The code for Addition::getName() and getSign() seems to be missing.

>> Do you mean at end of each file I should put \n?
Go to end of the file and hit ENTER.

[EDIT]
>> but I have implemented them!
The functions' signatures must match, are you sure you haven't forgotten e.g. const somewhere?

Now, I don't understand this. Let me post the three files, may be there is error under the hood
Thanks for ENTER thing ;)

IPlugin.h

#ifndef IPLUGIN_H
#define IPLUGIN_H

class IPlugin{
	
public:
	virtual const char* getName() const =0;
	virtual const char* getSign() const =0;
	virtual double doMath(double a, double b)=0;
	
};

/*
 *extern "C" {
	IPlugin* loadPlugin(){
		//load Plugin to the manager
	}
	
	void unloadPlugin(IPlugin* pluginInstance){
		//do cleaning here
	}
}

*/

#endif //IPLUGIN_H


Addition.h

#ifndef ADDITION_H
#define ADDITION_H

#include "IPlugin.h"
#ifdef MAKING_DLL
#define PLUGIN_EXPORTABLE __declspec(dllexport)
#endif


class Addition : public IPlugin{
public:
	const char* getName();
	const char* getSign();
	double doMath(double a, double b);
	
	
};


#endif //ADDITION_H

Addition.cpp

#include "Addition.h"
#include <windows.h>

bool APIENTRY DllMain(HINSTANCE hInstance, DWORD reason, LPVOID reserved){
	switch(reason){
		case DLL_PROCESS_ATTACH:
		//provess loads DLL
		break;
		case DLL_PROCESS_DETACH:
		//process unloads DLL
		break;
		case DLL_THREAD_ATTACH:
		//thread of app has loaded dll
		break;
		case DLL_THREAD_DETACH:
		//thread of an app has unloaded DLL
		break;
	}
	
	return true;
}


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

const char* Addition::getSign(){
	return "+";
}

double Addition::doMath(double a, double b){
	return a+b;
}


extern "C" {
	PLUGIN_EXPORTABLE IPlugin* loadPlugin(){
		return new Addition();
	}
	
	PLUGIN_EXPORTABLE void unloadPlugin(IPlugin* pluginInstance){
		delete pluginInstance;
	}
}

You are missing the const in the signatures, I take that you want to keep the methods const, so ..

Addition.h

<snip>

class Addition : public IPlugin{
public:
	const char* getName() const; /* < ---- const was missing */
	const char* getSign() const; /* < ---- const was missing */
	double doMath(double a, double b);

and also fix this same thing in Addition.cpp.

I think I have misunderstood the virtual functions concept.
I thought that was during declaration!
I will fix them now

That was the issue. It compiles DLL fine!

Now I have a lot of errors in main app. Let me try fix them first then I will be back

Member Avatar for ZootAllures

You should put the function return type before the PLUGIN_EXPORTABLE:

IPlugin* PLUGIN_EXPORTABLE loadPlugin()

and ditto for the other error.

warning: no newline at end of file

The last line in Addition.h isn't terminated, just add an Enter at the end of the line.

I have defined a vector to hold list of valid plugins and here is how I define it.

vector<IPlugin*> pluginList;//hold plugin lists

Now this causes throws of errors which I'm trying to find solution:

----------Build Started--------
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "PluginX_wsp.mk""
----------Building project:[ MathApp - Debug ]----------
mingw32-make.exe[1]: Entering directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp" -g -o ./Debug/PluginManager.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp" -g -o ./Debug/main.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:9: error: expected constructor, destructor, or type conversion before '<' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:12: error: `pluginList' does not name a type
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:16:7: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:3: error: `pluginList' does not name a type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double* PluginManager::getUserInput()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:10: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:12: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:13: error: `cin' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:14: error: `retVal' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double PluginManager::calculate()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: `HINSTANCE' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: expected `;' before "dll"
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `dll' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `LoadLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:26: error: `GetProcAddress' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:29: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:30: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:31: error: `vals' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:36: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:37: error: `FreeLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:39: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:40: error: `FreeLibrary' was not declared in this scope
mingw32-make.exe[1]: *** [Debug/PluginManager.o] Error 1
mingw32-make.exe[1]: *** Waiting for unfinished jobs....
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:9: error: expected constructor, destructor, or type conversion before '<' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:12: error: `pluginList' does not name a type
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:16:7: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: new types may not be defined in a return type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: note: (perhaps a semicolon is missing after the definition of `PluginManager')
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: extraneous `int' ignored
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: `main' must return `int'
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp: In function `int main(...)':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:14: error: `double PluginManager::calculate()' is private
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:5: error: within this context
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:7:2: warning: no newline at end of file
mingw32-make.exe[1]: *** [Debug/main.o] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
----------Build Ended----------
30 errors, 3 warnings

I have defined a vector to hold list of valid plugins and here is how I define it.

vector<IPlugin*> pluginList;//hold plugin lists

Now this causes throws of errors which I'm trying to find solution:

----------Build Started--------
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "PluginX_wsp.mk""
----------Building project:[ MathApp - Debug ]----------
mingw32-make.exe[1]: Entering directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp" -g -o ./Debug/PluginManager.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp" -g -o ./Debug/main.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:9: error: expected constructor, destructor, or type conversion before '<' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:12: error: `pluginList' does not name a type
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:16:7: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:3: error: `pluginList' does not name a type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double* PluginManager::getUserInput()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:10: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:12: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:13: error: `cin' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:14: error: `retVal' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double PluginManager::calculate()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: `HINSTANCE' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: expected `;' before "dll"
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `dll' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `LoadLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:26: error: `GetProcAddress' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:29: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:30: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:31: error: `vals' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:36: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:37: error: `FreeLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:39: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:40: error: `FreeLibrary' was not declared in this scope
mingw32-make.exe[1]: *** [Debug/PluginManager.o] Error 1
mingw32-make.exe[1]: *** Waiting for unfinished jobs....
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:9: error: expected constructor, destructor, or type conversion before '<' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:12: error: `pluginList' does not name a type
In file included from F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:1:
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:16:7: warning: no newline at end of file
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: new types may not be defined in a return type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: note: (perhaps a semicolon is missing after the definition of `PluginManager')
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: extraneous `int' ignored
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: `main' must return `int'
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp: In function `int main(...)':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:14: error: `double PluginManager::calculate()' is private
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:5: error: within this context
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:7:2: warning: no newline at end of file
mingw32-make.exe[1]: *** [Debug/main.o] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
----------Build Ended----------
30 errors, 3 warnings

Umm, maybe

#include <vector>
std::vector<IPlugin*> pluginList;//hold plugin lists

?

Thanks,
I forgot that all standard lib classes are in std namespace.
"using namespace std" is brain killer ;)

Now it gives me error that `pluginList' does not name a type
How comes seeing that I have just defined as the file below?n Should I make it typedef?

#ifndef PLUGINMANAGER_H
#define PLUGINMANAGER_H

#include "IPlugin.h"
#include <iostream>
#include <vector>

typedef std::string String;
std::vector<IPlugin*> pluginList;//hold plugin lists

class PluginManager{
	pluginList getValidPlugins(String path); //give us list of valid plugins
	double* getUserInput();
	double calculate();
}
#endif

>> Should I make it typedef?
That is up to you, i.e. how do you want the thing to work?

the function pluginList getValidPlugins(String path);
will load all valid plugin and return the list as a vector. I have already defined pluginList but errors errors errors
Below is full error log

----------Build Started--------
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "PluginX_wsp.mk""
----------Building project:[ MathApp - Debug ]----------
mingw32-make.exe[1]: Entering directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp" -g -o ./Debug/PluginManager.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
g++ -c "F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp" -g -o ./Debug/main.o "-I." "-IF:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/interfaces"
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:3: error: `pluginList' does not name a type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double* PluginManager::getUserInput()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:10: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:12: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:13: error: `cin' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:14: error: `retVal' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp: In member function `double PluginManager::calculate()':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: `HINSTANCE' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:20: error: expected `;' before "dll"
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `dll' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:24: error: `LoadLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:26: error: `GetProcAddress' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:29: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:30: error: expected unqualified-id before '[' token
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:31: error: `vals' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:36: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:37: error: `FreeLibrary' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:39: error: `cout' was not declared in this scope
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.cpp:40: error: `FreeLibrary' was not declared in this scope
mingw32-make.exe[1]: *** [Debug/PluginManager.o] Error 1
mingw32-make.exe[1]: *** Waiting for unfinished jobs....
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: new types may not be defined in a return type
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: note: (perhaps a semicolon is missing after the definition of `PluginManager')
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: extraneous `int' ignored
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:3: error: `main' must return `int'
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp: In function `int main(...)':
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/PluginManager.h:14: error: `double PluginManager::calculate()' is private
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:5: error: within this context
F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp/main.cpp:7:2: warning: no newline at end of file
mingw32-make.exe[1]: *** [Debug/main.o] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `F:/Projects/c++/Personal Projects/myFirstPlugin/PluginX/MathApp'
----------Build Ended----------
22 errors, 1 warnings

And the PluginManger.cpp is this

#include "PluginManager.h"

pluginList PluginManager::getValidPlugins(String path){
 // Iterate plugins dir, check for two C functions and load valid plugins	
}



double* PluginManager::getUserInput(){
	cout<<"Please Enter Values of x and y"<<std::endl;
	double x, y;
	double[] retVal;
	cin>>x>>y;
	retVal[0]=x;
	retVal[1]=y;
	return retVal;
}

double PluginManager::calculate(){
	HINSTANCE dll;
	typedef IPlugin* (*LOAD_PLUGIN)();	
	typedef void (*ULOAD_PLUGIN)(IPlugin*);
	//Load Lib -- but should be done by getValidPlugins
	dll = LoadLibrary("Addition.dll");
	if(dll!=NULL){
		LOAD_PLUGIN loadMe = (LOAD_PLUGIN)GetProcAddress("loadPlugin");
		if(loadMe!=NULL){
			IPlugin* plugin1 = loadMe();
			cout<<"Doing Some Math with "<<plugin1->getSign()<<std::endl;
			double[] vals = this.getUserInput();
			cout<<"The Result of "<<vals[0]<<plugin1->getSign()<<vals[0]<< "Is: "<<plugin1->doMath(vals[0], vals[1])<<std::endl;
		}
		
	}
	else{
		cout<<"Failed to Load DLL"<<std::endl;
		FreeLibrary(dll);
	}
	cout<<"Freeing DLL"<<std::endl;
	FreeLibrary(dll);
	
	
}

>> .. I have already defined pluginList but errors errors errors
>> Below is full error log ..
Hmm, the errors seem mostly pretty trivial (e.g. missing #includes, scope resolution ( std:: ) and function arguments).
So I suggest that you work through the error list (from top to bottom). Try solving one error at a time, then re-compile and see what is the output.
;)

PS.
This is not C++

double [] retVal;

This would be ..

double retVal[ <some const size here> ];

[EDIT]
Regarding this "double retVal[]", it is an array local to the function - so you must not return an address to it, because it's garbage as soon as the function returns. You need to re-think that one.

Thanks for reply. The error that have puzzled me is that one with
'pluginList' does not name a type
As I have shown you the code I have defined it here:

typedef std::vector<IPlugin*> pluginList;//hold plugin lists

So I don't know where to start. Once I fix this, i can go fixing others.
I'm still on google thoguh ;)

Sory for double posting. This can be deleted

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.