Why use LPDIRECT3DDEVICE9 vs. IDirect3DDevice9

Started by
10 comments, last by mattnewport 17 years, 8 months ago
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?
Advertisement
They aren't the same. LPDIRECT3DDEVICE9 is a IDirect3DDevice9 *.
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.
Yes the one needs a * and the other doesn't. I prefer the NonCapitalizedstyle more than the CAPPEDstyleOHCOMEON. But that's just preference.
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.
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;
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.
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.
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]
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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.

This topic is closed to new replies.

Advertisement