Skip to main content
gamedev.net
🔒 Locked

DX Create

Started by theonlymcc Oct 10, 2000 at 5:02 PM 8 replies 1.1k views
Original Post
theonlymcc
theonlymcc
Is it better to use the DirectDrawCreateEx function to create the object or to use the Initialize function? does it make a difference?
Gaiiden
Gaiiden
The Initialize() function is used only if go the dirty and gritty way - by creating the object directly through COM, which is a real pain (though good to know). It only accepts a GUID of the object you created.

If you are using DirectX v7, then use DirectDrawCreateEx(). It''ll return the IDirectDraw7 interface, and is much simpler. I don''t know of any major performance hits either way.

If you are using DirectX v6 or lower, you''ll have to first call DirectDrawCreate() to get the normal IDirectDraw object, then use QueryInterface() to get the latest DirectDraw version, IDirectDraw4.

NOTE

Make sure for DirectX 7 you are using LPDIRECTDRAW7 and for the earlier versions, first use LPDIRECTDRAW then query for LPDIRECTDRAW4.

==============================
\\// live long and prosper; \||/ die short and rot.
==============================
Drew Sikora
Executive Producer
GameDev.net
Aldacron
Aldacron
If you''re creating a commercial quality game, however, you should always go the COM way and use CoCreateInstance and Initialize instead of DirectDrawCreateEx. Using the DDCreateEx function will cause the program to crash if DX 7 is not on the system. Well, actually it will never run. The user will get a MessageBox stating that there is no such function in ddraw.dll. This is because you have to link with the import lib (ddraw.lib) and windows will load ddraw.dll automatically.

Now, if you use the COM method, you have no need to link the import lib and can handle the absence of DX 7 gracefully by either trying an earlier version, or by popping up a message box saying "You need to install DX 7."
mhkrause
mhkrause
Or instead of going to COM, just do a LoadLibrary/GetProcAddress.

Gaiiden
Gaiiden
Yeah, but if you error detect with FAILED you could display a message telling the user DirectX 7 isn''t installed, and you can exit with grace. I wish you could then switch to a lower version (v4) but the difference in functions and procedures would make that a pain in the ass - even if prepared for.

==============================
\\// live long and prosper; \||/ die short and rot.
==============================
Drew Sikora
Executive Producer
GameDev.net
Aldacron
Aldacron
Of course you should always use FAILED. But... you will never get to that point if you implicitly link to ddraw.lib and the app runs on a machine without DX 7. No prior version of DX contains a DirectDrawCreateEx macro. They all had DirectDrawCreate. Windows will notice this when it loads up ddraw.dll and your FAILED macro will never have a chance to check for any errors - meaning no graceful exit. Which is why you should use either COM or LoadLibrary/GetProcAddress to avoid specifically linking to ddraw.lib. Then you can exit gracefully.

As far as supporting previous versions in one app, you don''t need to do it if you don''t want to, but with a little bit of careful planning it can be done.
Gaiiden
Gaiiden
Ah, I see now. Yes, DirectDrawCreateEx() would cause an error if DirectX 7 wasn't there. That's easily fixed though, by doing it the more round-about way (calling DirectDrawCreate() and then QueryInterface()) right? Then you wouldn't get a terminal error you can't handle.

And yes, it is possible to handle earlier DirectX versions. I didn't say it was impossible, I just said it would be a pain to plan for (and if you didn't plan in advance.... ugh.)

BTW: I just noticed you're from Korea. You a mad Starcraft fan like the rest of them? It's crazy down there!

==============================
\\// live long and prosper; \||/ die short and rot.
==============================

Edited by - Gaiiden on October 12, 2000 7:54:27 AM
Drew Sikora
Executive Producer
GameDev.net
Aldacron
Aldacron
I played Starcraft once and never looked at it again. Actually, my info is a bit misleading. I'm American. I've just been living here in Seoul for nigh on 10 years. I keep the From:Seoul up there so any Korean programmers who drop by GDNet might contact me. Happened a couple of times. But you're right, it is crazy. People gather around at 'PC Rooms' and play (or just watch others play) for hours on end. Not to mention they actually televise Starcraft tournaments quite often.

Back to the DX issue -

I remember hearing a long while back (right after DX 7 was released) a reason why you shouldn't create a DDraw7 object via QueryInterface, but I can't remember what it was. I've been looking through the Docs and it says nothing about it, but I know I read it on a mailing list/message board/article somewhere.

Edited by - Aldacron on October 12, 2000 9:54:29 AM
furby100
furby100
You shouldn''t use QueryInterface because then you can''t QueryInterface for a D3D7 object.

------------------------------
#pragma twice


sharewaregames.20m.com

Gaiiden
Gaiiden
Oh, OK. Personally I love Starcraft and living in Korea would be awesome - but seeing as I don''t speak the language, oh well. I always got my ass kicked on BNet anyways.

So you can''t get a D3D interface if you use QueryInterface() for DD huh? Well, I haven''t gotten that far along yet, sadly (so it''s not really an issue for me) but thatnks for the warning furby, I''ll have to remember that.

==============================
\\// live long and prosper; \||/ die short and rot.
==============================
Drew Sikora
Executive Producer
GameDev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.