Jump to content
  • Advertisement
Sign in to follow this  
mrheisenberg

Is it safe to use IUnknown* for every class that has a DirectX object in it?

This topic is 1930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For instance, instead of using ID3D11Buffer* in your mesh class, to use IUnknown or isntead of ID3D11PixelShader* to use IUnknown again.Since they inherit from it, casting and passing to functions that require those types shouldn't be a problem, right?

Share this post


Link to post
Share on other sites
Advertisement

That's right - but by passing a reference/pointer to an IUnknown instance you are limited to only using its interface unless you re-cast it back to the original subclass.  The only interfaces that the IUnknown interface provides are AddRef and Release, so I don't think this would be a very good way to go though.

Share this post


Link to post
Share on other sites

This seems fundamentally unsafe to me.  In order to do anything useful with the IUnknown you're talking about having to cast it back to it's original interface, but you don't know what the original interface was.  Sure, you may say that "I only put vertex shaders into this member so this IUnknown must be a vertex shader", but that fails to protect you against programmer error, which really misses the point of stronger typing.

Share this post


Link to post
Share on other sites

You don't have to cast it directly back to its original interface, you can use QueryInterface.

Share this post


Link to post
Share on other sites

You don't have to cast it directly back to its original interface, you can use QueryInterface.

 

That would be safer, yes, but at the expense of having to Release the returned interface after every use.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!