开发者

accessing a static property via COM

is it possible to access a static property of a COM object without creating an instance of the object?

my situation is this: i have an unmanaged application (written in delphi). this application exposes a COM-based plugininterface. until now i only wrote managed plugins in c#. plugins provide their info (name, author, ..) via a static property that returns an instance of PluginInfo (which implements IPluginInfo). this static property i can access on the managed plugins using http://managedvcl.com.

now i want to write unmanaged plugins on the same interface. i can load them using:

plug := CreateComObject(TGuid) as IMyPlugInterface;

and they run, but i don't know how to read out their PluginInfo.

so the question again is: is there another way than implementing IPluginInfo in the plugin-class and only accessing the info after i have cre开发者_高级运维ated an instance of the plugin?


It may not be as "elegant" as the static property provided by the C# plug-in architectures you are used to, but you could provide an exported function in the COM DLL that returns an IPluginInfo. By convention this exported function would have the same name in every plug-in DLL designed to operate in your architecture.

The host application would obtain the proc address for the exported function dynamically at runtime then call it to obtain the IPluginInfo interfaced object for that specific plug-in DLL. The mechanics for this could all be encapsulated in a class for your plug-in architecture, hiding the implementation details.

It would take very little work to reach a point where your plug-in architecture would be just as convenient to use and code against as the C# infrastructure you are more used to.


No. Delphi's interfaces are implemented as virtual methods (basically) on an object instance, and AFAIK can't accept static members. That would probably make a useful enhancement, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜