Click here to Skip to main content
15,887,343 members
Please Sign up or sign in to vote.
1.27/5 (3 votes)
See more:
I am attempting to make a plugin API for my application, in order to do this, i need to be able to hook into the application itself and be able to grab, and maybe set information, what would be the best way to go about doing this, I would like, if possible, to be able to do this using only native C# and not have to use any external DLLs.

-Jordan
Posted
Comments
Jean A Brandelero 13-Aug-13 9:18am    
It's not rocket science, but its not easy.
Look for .Net Reflection tutorials, create interfaces for your "plugins" and link events to the methods. I do this in my projects and it runs nice.
Sicppy 13-Aug-13 9:24am    
What exactly do you mean by linking methods to events, and I am using .Net reflection for loading the DLLs dynamically.
Jean A Brandelero 13-Aug-13 14:11pm    
Look my solution again, just added a simple way to get values from main assembly.

Just searched a little and found this:
A Flexible Plugin System[^]

Edit:
you can simple use this to get a value from the main exe:
int x = (int)System.Reflection.Assembly.GetEntryAssembly().GetType("SharedVarsClass").GetField("SharedVar").GetValue(null);
 
Share this answer
 
v2
Comments
Sicppy 13-Aug-13 9:26am    
That is full fledged plugin loading and implementing API, which isn't what i'm looking for, I have already created the plugin loading system, i just need to be able to grab realtime variables from the host application.
Sergey Alexandrovich Kryukov 13-Aug-13 10:53am    
Sorry, this is a pretty bad article. It looks like the names (hard-coded strings are used), and the most difficult problem (unloading plug-ins) is just mentioned but the solution is not shown. Very weak work, I cannot recommend it at all.

At the same time, I covered all these topics in my past answers in much greater detail. (I understand those answers are hard to read, but I did not happen to write an article on it :-(. Please see my answer.

—SA
First, you can use the Microsoft MEF framework:
http://en.wikipedia.org/wiki/Managed_Extensibility_Framework[^],
http://mef.codeplex.com/[^],
http://msdn.microsoft.com/en-us/library/dd460648%28VS.100%29.aspx[^].

You can do it yourself, especially if you need it as simple as you really need. Please see my past answer, only one, but it has links to my other past answers, another 7. They cover the topic in detail: What is the use of plugin in general[^].

—SA
 
Share this answer
 
Comments
Sicppy 13-Aug-13 14:22pm    
MEF is starting to look like a serious possibility especially considering it comes with the .NET framework, but could you give me an example of how i could pass a variable back and forth through the API and host application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900