Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 mrheisenberg   Members   -  Reputation: 356

Like
0Likes
Like

Posted 02 April 2013 - 04:29 PM

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?



Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 5164

Like
1Likes
Like

Posted 02 April 2013 - 06:54 PM

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.



#3 mhagain   Crossbones+   -  Reputation: 8142

Like
1Likes
Like

Posted 03 April 2013 - 04:45 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 phil_t   Crossbones+   -  Reputation: 3949

Like
0Likes
Like

Posted 03 April 2013 - 08:26 AM

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



#5 mhagain   Crossbones+   -  Reputation: 8142

Like
0Likes
Like

Posted 03 April 2013 - 08:45 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS