多实例COM对象 [英] Multi instances COM object
问题描述
我在C#中使用C ++编写的COM对象。我只是通过新建创建实例。我需要许多这样的对象。但是其他所有新实例都不会创建新实例,而只会提供第一个对象的引用。那就是为什么我对数据一团糟。是否可以每次获取新实例?还是我应该在COM中实现IClassFactory来实例化而不是单例?
我在具有ATL支持的VC 2010中用COM制作了COM。而且我在哪里以及如何实现IClassFactory方面遇到麻烦。
I use a C++ written COM object in C#. I just create instance through "new". I need numerous of such objects. But every other "new" doesn't create new instance, but only gives reference on first object. Thats why I have a mess with data. Is it possible to get new instance every time? Or I should realize IClassFactory in my COM to instantiate not singleton? I've made COM with master in VC 2010 with ATL support. And I have a trouble where and how to realize IClassFactory.
推荐答案
您需要实现 IUnknown , IClassFactory 。根据您在做什么,您可能想实现 IDispatch 和 IErrorInfo 也是如此。它涉及很多,所以我在这里不做详细介绍。以下三篇文章应涵盖您所需要的几乎所有内容:
You need to implement IUnknown, IClassFactory. Depending on what you're doing you may want to implement IDispatch and IErrorInfo as well. It's quite involved so I won't go into the details here. The following three articles should cover pretty much everything that you are after:
- Step by Step COM Tutorial
- Understanding Classic COM Interoperability With .NET Applications
- Fundamentals of ATL COM Objects
这篇关于多实例COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!