Why use LPDIRECT3DDEVICE9 vs. IDirect3DDevice9

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

Recommended Posts

I am starting to learn DX and see that the two are the same the former is a typedef but is their any other good reason to use it instead of the IDirect3DDevice9 class?

Share on other sites
They aren't the same. LPDIRECT3DDEVICE9 is a IDirect3DDevice9 *.

Share on other sites
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 on other sites
Yes the one needs a * and the other doesn't. I prefer the NonCapitalizedstyle more than the CAPPEDstyleOHCOMEON. But that's just preference.

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 on other sites
Quote:
 Original post by SiCraneThey 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 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 on other sites
Quote:
 Original post by SiCraneTwo 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 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 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 on other sites
Quote:
 Original post by SiCraneOf 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 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.