Access a static property through COM

Is it possible to access the static property of a COM object without instantiating the object?

my situation : I have an unmanaged application (written in delphi). This application provides a plugininterface COM interface. so far I have written only managed plugins in C #. plugins provide their information (name, author, ..) through a static property that returns an instance of PluginInfo (which implements IPluginInfo). this is a static property I can access managed plugins using http://managedvcl.com .

Now I want to write unmanaged plugins on the same interface. I can download them using:

plug := CreateComObject(TGuid) as IMyPlugInterface; 

and they start, but I don’t know how to read their PluginInfo.

so the question is again : is there any other way than implementing IPluginInfo in the plugin class and only accessing the information after I created the instance of the plugin?

+4
source share
2 answers

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

The host application will obtain the proc address for the exported function dynamically at runtime, and then call it to obtain the IPluginInfo conjugate for this particular DLL module. The mechanics for this can be encapsulated in a class for your plugin architecture, hiding implementation details.

It will take very little work to reach the point at which your plug-in architecture will be just as easy to use, and will be used for code as the C # infrastructure that you are more used to.

+2
source

Not. Delphi interfaces are implemented as virtual methods (mostly) on an instance of an object, and AFAIK cannot accept static elements. This would probably make a useful improvement.

+1
source

Source: https://habr.com/ru/post/1303847/


All Articles