Advertisement Jump to content


This topic is now archived and is closed to further replies.

Shannon Barber

COM & DirectX References

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

Is it possible to create a reference to a DirectX object? (or any COM object for that matter...) This appears to work...
class CFrame
CFrame(hInstance newInst, int newShowCmd, IDirectDraw7* lpDD7): DD7(*lpDD7)
//WinAPI stuff..

IDirectDraw7& DD7;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
IDirectDraw7* lpDD7;
hr = DirectDrawCreateEx(NULL, (VOID**)&lpDD7, IID_IDirectDraw7, NULL);

CFrame* Capsule;

Capsule = new CFrame(hInstance, nShowCmn, lpDD7);


Yes it works! Object.Method(); is faster than pObject->Method(); right? I'm not missing something that makes them same, am I? If there's a single other person out there who does not think I am delusional, I'd be happy to hammer out some object designs that take advantage of this... Edited by - Magmai Kai Holmlor on 6/26/00 10:08:32 PM

Share this post

Link to post
Share on other sites

is faster than

Wrong For 2 reasons. Here''s 3 variable declarations:

Object LocalObject;
Object* HeapObjectPtr = new Object;
Object& HeapObjectRef = *HeapObjectPtr;

First issue: A reference is not the same as a local object. It is merely a nicely-disguised pointer. So, just because:
look similar, it doesn''t mean that the second one is not dereferencing a pointer. Behind the scenes, it is the same as HeapObjectPtr->Method().

Second issue: All calls to Method(), since it is a member function, will be translated internally to something like this:

Method(Object* aPtr, any other parameters);

For LocalObject, it will just pass its address (which will correspond to a position on the stack) as the ''this'' pointer. For HeapObjectPtr, it will just pass HeapObjectPtr in directly. For HeapObjectRef, it will pass in HeapObjectRef as a pointer, as they are fundamentally the same thing to the underlying system.

So the actual call itself is almost exactly the same. And accessing member variables from within Method() will be the same, as they will all be accessed through the ''this'' pointer, ie. dereferenced. The fact that all 3 forms translate to pretty much the same thing means that the misconception in the first issue is irrelevant... but I wanted to point it out anyway

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!