Sign in to follow this  

Why use LPDIRECT3DDEVICE9 vs. IDirect3DDevice9

This topic is 4160 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

The typedef LPDIRECT3DDEVICE9 is just there to maintain a standard and ease of use. Since realistically, you're only going to ever use a pointer to most Direct3D member classes, creating long pointer typedefs for each one was the obvious thing to do.

Share this post


Link to post
Share on other sites
I've seen this kind of thing done so that you could, if you wanted replace LPDIRECT3DDEVICE9 with a templatized safe pointer class without changing your code. I've no idea whether this was thinking behind the DX pointer types.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
They aren't the same. LPDIRECT3DDEVICE9 is a IDirect3DDevice9 *.


Ok, but I can make them the same by adding the *to it and now its a pointer my point was why the typedef...


LPDIRECT3DDEVICE9 == IDirect3Device9 *myD3DDevice;



Share this post


Link to post
Share on other sites
Two reasons: One, you never deal with a variable of type IDirect3DDevice9. You do however deal with IDirect3DDevice9 * and IDirect3DDevice9 ** all the time. Two, in the off chance that future platform changes alters the meaning of a long pointer. In old DOS days a long pointer mean a __far *, not just a *. There's a non-zero chance in the future something analagous might occur and then only the typedef will need to change, with minimal effects to code that uses the typedef.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Two reasons: One, you never deal with a variable of type IDirect3DDevice9. You do however deal with IDirect3DDevice9 * and IDirect3DDevice9 ** all the time. Two, in the off chance that future platform changes alters the meaning of a long pointer. In old DOS days a long pointer mean a __far *, not just a *. There's a non-zero chance in the future something analagous might occur and then only the typedef will need to change, with minimal effects to code that uses the typedef.


Thanks that answers my question and makes logical sense.

Share this post


Link to post
Share on other sites
For future reference, here is a little guide to hungarian notation (what the Win32 APIs use). Not all of the MS standards are there, but it gives you a good idea of how to interpret typedefs and parameter names. It might come in handy when you see a m_LpTSzStrHereIsALongString variable [wink]

Share this post


Link to post
Share on other sites
Of course that link is completely irrelevant to this discussion as it has no mention of what the lp prefix means, nor what a long pointer is nor why it would be typedef'ed.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Of course that link is completely irrelevant to this discussion as it has no mention of what the lp prefix means, nor what a long pointer is nor why it would be typedef'ed.

Seeing as the basis of this thread was brought upon by confusion of a hungarian prefix, I hardly see why that page is completely irrelevant. Sure, it doesn't mention lp, but a quick search didn't turn up any end-all-be-all guide. And with the large number of prefixes in use, I can see why.

Share this post


Link to post
Share on other sites
Better yet, don't use either of them - #include <comdef.h> before you #include any d3d headers and you can use the auto typedef'd smart pointers instead: IDirect3Dxxx9* or LPDIRECT3Dxxx9 becomes IDirect3Dxxx9Ptr, an instance of the _com_ptr_t smart pointer template. That way you don't have to worry about manually tracking reference counts.

Share this post


Link to post
Share on other sites

This topic is 4160 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this