1

I am looking into DirectShow samples from Windows SDK. Many of the classes feature non-default constructor. How those constructors are called? Who supplies arguments?

Can I use those classes in C++ programs without registration? If so I could use class constructor directly.

If I use a COM class without registration what happens in the following code fragment:

Foo * foo = new Foo(.....); // note, not using CoCreateInstance
Bar * bar = foo->QueryInterface(...);
bar->Release();
delete foo; // CRASH?

Thank you!

1
  • You don't know how Release is implemented in the general case (it could even be a no-op, or use another memory allocator). Here, it is likely doing delete this. You should use CoCreateInstance + Release, this is the only safe thing to do. Commented Apr 6, 2012 at 15:49

2 Answers 2

2

It has nothing to do with COM, it is just the framework is built this way and constructor arguments in DirectShow BaseClasses are necessary to get everything together - the class, the ancestor, the instantiating factory.

Using COM class without registration might be or might not be possible. I suspect you might be interested in using DirectShow filter without registration instead, and there is a good article on the topic: Using Filters Without Registration.

Sign up to request clarification or add additional context in comments.

Comments

2

A C++ class that's exposed as a real COM coclass cannot in general have a constructor that takes arguments. There's no mechanism for the COM client code to pass arguments to the CoCreateInstance() function. A COM interface typically has an Initialize() method to supply required initialization. Technically that can be doctored as well, CoCreateInstance is just a convenience function that hides the class factory (IClassFactory). A custom class factory with a custom CreateInstance() method is possible, but rarely done.

Microsoft uses the interface-based programming model that's common in COM code in non-COM code as well. DirectX is a good example. Think of Direct3DCreate9Ex() as the class factory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.