I have to provide functionality to be used by both new C# applications and a legacy C++ (VC6!!) application. So I'm planning on exposing the interfaces via in-process COM. One of the issues is that the new functionality requires carrying some state across uses of these COM interfaces although the legacy application doesn't have a mechanism for passing state information.
This is data analysis
like:
- Collect reference data for calibration. (legacy)
- Compute calibration. (legacy sw using my new code)
- Collect sample data. (legacy)
- Analyze using calibration. (legacy sw using my new code)
Probably repeat 3 & 4 for additional sample data.
Possibly repeat from 1 for additional data sets.
The legacy application is a third-party application for which we can write limited C++ plug-ins. The invocation of these are all independent.
This is all within a single execution of the application, so I thought that having a singleton "manager" class that held the state while the application was executing should keep things from going away while there are no COM references held.
If this assumption is not true, please let me know!
As I recall, there's no COM equivalent to invoking a C# static method/property to get the singleton instance of the "manager" class.
(Or am I wrong on this? It's been
quite awhile since my COM heyday.)
So the question is how do I wrap the "manager" class interface in C# so all
CoCreateInstance()
in the C++ get the interface to the same "actual" instance?
(I.e., steps 2 and 4, above, will each call
CoCreateInstance()
for the "manager" interface, and will call
Release()
on that interface.)
Of course, suggestions of different strategies will be considered.
What I have tried:
I'm very familiar with making a C# singleton class.
I also have fairly recent experience exposing C# interfaces via COM.
The complication here is Singleton.
I haven't "tried" coding this yet.
One thought I had was a hack of a meta-class that could be
CoCreateInstance()
'ed and had a single property which returned the actual singleton instance interface. (:thumbsdown:)
Another was to have the COM exposed class implement the same interface as the singleton but have all method and property implementations just call the functionality on the singleton instance.
Any other suggestions?