开发者

COM IUnknown and do I need a pointer to it first before calling CoGetClassObject?

开发者 https://www.devze.com 2022-12-31 00:11 出处:网络
In COM, when you want to create an instance of some COM Server object, do you first need to get a pointer to it\'s IUnknown interface and only then create a class object using 开发者_开发知识库CoGetCl

In COM, when you want to create an instance of some COM Server object, do you first need to get a pointer to it's IUnknown interface and only then create a class object using 开发者_开发知识库CoGetClassObject?

As far as I understand it, IUnknown is used to manage object lifetimes, so from my understanding, whatever object the client wants to create, one needs a pointer to it's IUnknown interface implementation first.

Sound correct? If not, can anyone tell me how it works?


IUnknown manages the lifespan of an existing COM object. Before the object is created, there is no IUnknown pointer to speak of.

CoGetClassObject is used to get the IUnknown interface for an object that is expected to create the objects of interest. I.e., it is an object factory, an usually implements IClassFactory, which declares the CreateInstance method that you use to create objects.

Instead of using class factories explicitly, it is often simpler to just call CoCreateInstance.

0

精彩评论

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