How to share functions, objects from the main APP to the plugin dll?  
Author Message
Attila Strba





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

Hello everyone,

I guess this subject was already discuseed few times in this Forum but still I would like to hear some more oppinions:
I am developing an application which main task is to receive data through the SerialPort (using a SerialLibrary) and to process and display these ddata in the GUI. This application should have also an API which supports plugins - dll files that are loaded dynamicali during runtime.

The application API should be an interface for the plugins and it would have two main tasks:
1. Load the plugin dlls upon execution and initialize their functions from the DLL (with the help of LoadLibrary and GetProcAddress).
2. Offer an interface for the plugins to access the main application resources with other words, share some of the main application objects: SerialLibrary function, some GUI resources (ListBoxes, Menus), some processing functions etc.

The project is developed in Visual C++, with MFC support.

My question is:
My main issue is according to the API development. How to create this API as an interface in the main application so that the plugin DLL's can use resources from the application. I have searched through the internet and have found several solution but I don't know which is the best:

1. create a class with virtual functions that will work like an interface, the header file of this class will be included to the plugin project; the virtual class would be inherited and created in the main project and it's pointer would be given to the plugin.

2. All functions that the application would like to share with the plugins to put in an DLL. This DLL would be linked to all the plugins and also to the main application.

3. The plugins would be defined as COM objects

4. Create a function table where resides all function addresses of the plugins and the shared main application functions and objects

I would be very gratefull for any suggestion. Thanks a lot, greetings

Attila




Visual C++16  
 
 
Martin Richter





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

My question is:
My main issue is according to the API development. How to create this API as an interface in the main application so that the plugin DLL's can use resources from the application. I have searched through the internet and have found several solution but I don't know which is the best:

1. create a class with virtual functions that will work like an interface, the header file of this class will be included to the plugin project; the virtual class would be inherited and created in the main project and it's pointer would be given to the plugin.

2. All functions that the application would like to share with the plugins to put in an DLL. This DLL would be linked to all the plugins and also to the main application.

3. The plugins would be defined as COM objects

4. Create a function table where resides all function addresses of the plugins and the shared main application functions and objects

I see no real difference bew**** 1+4. The vtable is an array of functions.

If the interface is complex choose 3:Plugins are COM Objects that get a corresponding COM Interface from the main application. So the Pluggin can query the main aplications for objects to perform the actions.

If the interface is easy and small choose 1.

COM allows an easy abstaction of the data and you have a clear and secure level to isolate data from the man program and data from the plugin.



 
 
Attila Strba





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

Hi Martin,

thanks for the answer. It helped a lot. I guess the interface is simple sofar, but with time it will grow and become robust. So I guess I will try the COM implementation.

The only drawback, I have no idea about COM application development, I will search the web, but maybe if you would have a link to a good COM tutorial web site - especially according plugin and API development subject I could really appriciate it. Thank you again.

greetings

Attila




 
 
Martin Richter





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

Sry I can't help you with such a link.

For all my COM stuff I used ATL. And the book "ATL-Internals" covers a lot. But AFAIK there is nothing in it, that get in to detail on your problem.



 
 
Attila Strba





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

Hi again,
Thanx for the answer.
I checked out how to implement a COM interface for a the Application and the DLL and it seems pretty complicated for C++.
I am now considering maybe doing the whole implementation in C# while it seems easyer. What is your oppinion

greetings,

Attila

 
 
Martin Richter





PostPosted: Visual C++ General, How to share functions, objects from the main APP to the plugin dll? Top

Due to the reflection mechanisms a .NET implementation wouldbe easier. But than your complete program should be .NET!

For a newcomer the COM stuff is quite overwelming but managable.