Hi All,
I'm in the process of working on an application under Visual Studio 2005, C++/CLI. In the past, I have coded many apps under C++ and when I've wanted to allow "plugins" to be written by 3rd parties or myself to enhance a product after an initial release, I tended to provide a DLLs, and dynamically load "plugin" DLLs at runtime with class factories etceteras facilitating the process.
Now, I'm moving on to the new C++/CLI language, I want to take advantage of the way .NET works, but am not sure of the "good" way to go about it, hence this question!
At first, things seem pretty simple. Let's say I have my product, and in a DLL is something like:
namespace MyNamespace
{
public ref class MyPlugin abstract
{
// all plugin members, methods, virtuals etc
};
};
Then, easily enough, someone with Visual studio can create a reference to this DLL, and go:
namespace 3rdPartyPlugin
{
public ref class 3rdPartyClass : MyNameSpace::MyPlugin
{
// 3rd party plugin implementation
};
};
Now, when the app loads, I could have an XML file which described these things:
<approot>
<plugins>
<plugin name="3rdpartyPlugin" lib="3rdparty" class="3rdPartyPlugin.3rdP
artyClass"
/>
</plugins>
</approot>
During loading, my application can instantiate this plugin (assuming the .dll is in the right location!):
Object^ pPlugin(AppDomain::Current
Domain->Cr
eateInstan
ceAndUnwra
p(strLib, strClass));
MyPlugin^ pInstance(dynamic_cast<MyP
lugin^>(pP
lugin));
if(!pInstance) // cast failed, not a MyPlugin?
{
};
Is this the best way to go about it? How would I add my product .DLL to a GAC so that rather than browsing for my DLL, the developer selects the namespace alongside all the Microsoft ones? Is there an easy way for my application to locate DLLs that are plugins?
Sorry for so many questions. I have it working, but am not convinced I've done it in the best way.
Thanks in advance.
Start Free Trial