• Advertisement

Archived

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

QueryInterface or not?

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

I'm reading Tricks of the Windows... and in the DirectDraw section the author first creates a LPDIRECTDRAW object and then uses QueryInterface to get the LPDIRECTDRAW4 object. Now I was using that and all was fine but then I saw a tutorial on gamedev (http://www.gamedev.net/reference/articles/article1077.asp) where the author skipped the QueryInterface step and just created a LPDIRECTDRAW7 object from the start. Which method is the prefered way? Also with all these LPDIRECTDRAW4's and LPDIRECTDRAW7's flying around where do I go to see which interface is the newest one? [edited by - punx409 on January 22, 2003 12:09:21 AM]

Share this post


Link to post
Share on other sites
Advertisement
As I know there are 3 ways to get DirectDraw Object
1)CoCreateInstance():
// initialize COM
CoInitialize(NULL);

// create the object
CoCreateInstance(CLSID_DirectDraw, NULL, CLSCTX_ALL, IID_IDirectDraw7, (void**)&lpdd7);

// initialize the object
lpdd7->Initialize(NULL);

2)Using DirectDrawCreate to get IDirectDraw Object first and then using that object to query IDirectDraw object with version you like (say: IDirectDraw7)
// get the IDirectDraw interface pointer
if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
{
// error-handling code here
}

// query for IDirectDraw7 pointer
if (FAILED(lpdd->QueryInterface(IID_IDirectDraw7, (void**)&lpdd7)))

{
// error-handling code here
}
else
{
// success! release IDirectDraw since we don''t need it anymore
lpdd->Release();
lpdd = NULL;
}

3)Using DirectDrawCreateEx()

DirectDrawCreateEx(
GUID FAR *lpGuid,
LPVOID *lplpDD,
REFIID iid,
IUnknown FAR *pUnkOuter
);



you should use the 3th method because you can get DirectDraw Object just one call. Be sure to check if the function FAILED or SUCCESS using FAILED() and SUCCEED() macros.

Hope it help

Share this post


Link to post
Share on other sites

  • Advertisement