Archived

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

KaMiKaZ

Problem with initializing directx

Recommended Posts

hi! after reading about half of "tricks of the windows game programming gurus", i decided to both start writing actuall directx code and to make my own library rather than use the t3d ones. newayz, in my game_init() function, which looks like this: int Game_Init() { if(FAILED(DirectDrawCreate(NULL,&lpdd, NULL))) { //error!! return(0); } if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4))) { //error!! return(0); } if(lpdd) { lpdd->Release(); lpdd = NULL; } if(FAILED(lpdd4->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) { //error!! return(0); } if(FAILED(lpdd4->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT,SCREEN_BPP,0,0))) { //error!! return(0); } } i come across a few errors that are somewhat strange while compiling. first, it says that IID_IDIRECTDRAW4 is an "unrefrencecd identifier". when looking in the directxsdk help, it says that a "Reference identifier of the interface being requested" should be passed... im a little confused there whether i have to declare iid_idirectdraw4 and define it somehow or it''s a flag or somethin else (oww my head hurts from all this!) the second error says that there isn''t 5 parameters in queryinterface(), which i know has 5... any help wud be appreciated! thanx, ~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
your going about it all wrong.
here is my init function:

HRESULT InitDirectDraw()
{

// Obtain a pointer to an IDirectDraw7 interface.
DirectDrawCreateEx(NULL, (VOID**)&lpDirectDraw, IID_IDirectDraw7, NULL);

// Set the cooperative level.
lpDirectDraw->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN|DDSCL_ALLOWREBOOT);

// Change the display mode.
lpDirectDraw->SetDisplayMode(nWidth, nHeight, nBPP, 0, 0);

DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX|DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount = 1;

// Create the primary surface with one back buffer.
lpDirectDraw->CreateSurface(&ddsd, &lpddsPrimary, NULL);

DDSCAPS2 ddscaps; ZeroMemory(&ddscaps, sizeof(DDSCAPS2));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;

// Get a pointer to the back buffer.
lpddsPrimary->GetAttachedSurface(&ddscaps, &lpddsBack);

return D3D_OK;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oh ya and make sure to link with dxguid.lib and ddraw.lib

example:

#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")
#include <windows.h>
#include <ddraw.h>

Share this post


Link to post
Share on other sites
annon, i think ur way wud work if i waz using directx 7 or 8 or somethin, but r/now im using directx 6.0, so there is no directdrawcreateex function.. everything else applies, but that doesn''t really help 2 much... thanx neway. can ne1 else using v 6.0 help me?
thanx,
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
aaaaaah! now the compiler doesn''t recognize LPDIRECTDRAW4 as a data type... somethin''s not right! i set the compiler to link to ddraw.lib and dxguid.lib, and also included ddraw.h . i have version 6.1 of the sdk installed.. grrrrrrrrrrrrrrrrrrr... any help wud b appreciated... the sooner the beter!
thanx,
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the code I posted is for DirectDraw 7.
dd7 is what you should be using.

and if you''re using version 6 you shouldnt be trying to obtain a pointer to a version 4 interface.

that makes no sense.

Share this post


Link to post
Share on other sites
annon... thanx but no thanx. i''m trying to learn directx 6 first! at v 6.0, all the interface versions were not caught up (ie some interfaces might be version 1, some 4, some 2, etc...) so that''s why directdraw is @ version 4. pleaz ne1 else know how to fix this?? it makes no sense at all. for the record, im using msoft visual c++ 6.0 introductary edition, and i''ve manually included ddraw.h, and linked to dxguid.lib and ddraw.lib thru the project->settings->link.
thanx
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
Never link to a library file through the projects->settings->link, you should always manually include then in your project. Don''t ask me why, just do it.

X4J

Share this post


Link to post
Share on other sites
im still getting the same errors... i manually linked by using this code:

#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")

i think dis is the right way to do it... but those stupid errors...
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
aaaaaaaahhhhh! still no luck. here''s what the top of my code looks like:

#define INITGUID
#include // include important windows stuff
#include
#include
#include // include important C/C++ stuff
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include



#include // include DirectDraw
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")

ne1 else have ne ideas?
thanx,
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
quote:
Original post by KaMiKaZ
hi!
after reading about half of "tricks of the windows game programming gurus", i decided to both start writing actuall directx code and to make my own library rather than use the t3d ones. newayz, in my game_init() function, which looks like this:


int Game_Init()
{
if(FAILED(DirectDrawCreate(NULL,&lpdd, NULL)))
{
//error!!
return(0);
}
if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd4)))
{
//error!!
return(0);
}
if(lpdd)
{
lpdd->Release();
lpdd = NULL;
}
if(FAILED(lpdd4->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
{
//error!!
return(0);
}

if(FAILED(lpdd4->SetDisplayMode(SCREEN_WIDTH,
SCREEN_HEIGHT,SCREEN_BPP,0,0)))
{
//error!!
return(0);
}


}

i come across a few errors that are somewhat strange while compiling. first, it says that IID_IDIRECTDRAW4 is an "unrefrencecd identifier". when looking in the directxsdk help, it says that a "Reference identifier of the interface being requested" should be passed... im a little confused there whether i have to declare iid_idirectdraw4 and define it somehow or it's a flag or somethin else (oww my head hurts from all this!)

the second error says that there isn't 5 parameters in queryinterface(), which i know has 5... any help wud be appreciated!
thanx,
~~KaMiKaZ~~



Don't listen to what most of the guys said as they don't know what the hell they are talking about since most of them didn't bother to even read your original message. Second, your problem is that you didn't set the search path for the DX libs and Include in your VC++ Settings. Go to TOOLS->Options->Directory menu and add the path to the DX Libraries and Includes as the ones that come with VC++ 6.0 are out of date.

That will solve all your problems...


"And that's the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP's Invasive Production Activation Technology!

"gitty up" -- Kramer

Edited by - Cyberdrek on August 17, 2001 10:07:47 AM

Share this post


Link to post
Share on other sites
thanx Cyberdrek... but i've had that set up the whole time, and i'm still getting the errors. aaaaaaah! this is really frustrating. anything else that i may have forgotten?
thanx,
~~KaMiKaZ~~

Edited by - KaMiKaZ on August 17, 2001 10:14:41 AM

Share this post


Link to post
Share on other sites
Hey,
I tried compiling the code on my system and didn''t get any of the strange errors you were. I have the DX8 SDK but am using DirectDraw7 so i''m not too familiar with what you''re doing. I changed the lpdd4 to just the lpdd and it seems to compile ok, but doesn''t run , it gets a fatal exception or something when trying to set the display mode. What I would do is start a new project and copy the code over and re-setup your workspace, sometimes that helps for some reason (I use MSVC++ 6.0), but all I can think of is something must be set up wrong. You also might want to consider going to directdraw7, the DirectDrawCreateEx makes things pretty easy. Hope that helps, good luck.

__________________________________________
We get signal.
There are bombs exploding all around us!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Cyberdrek

Don''t listen to what most of the guys said as they don''t know what the hell they are talking about since most of them didn''t bother to even read your original message. Second, your problem is that you didn''t set the search path for the DX libs and Include in your VC++ Settings. Go to TOOLS->Options->Directory menu and add the path to the DX Libraries and Includes as the ones that come with VC++ 6.0 are out of date.

That will solve all your problems...




quote:
Original post by KaMiKaZ
thanx Cyberdrek... but i''ve had that set up the whole time, and i''m still getting the errors. aaaaaaah! this is really frustrating. anything else that i may have forgotten?
thanx,
~~KaMiKaZ~~

Edited by - KaMiKaZ on August 17, 2001 10:14:41 AM



How does that crow taste Cyberdrek?
Seems like you don''t know what you are talking about either

Share this post


Link to post
Share on other sites
rixter, if i use DX8.0, and directdraw7 respectivly, will i still be able to do everything besides directdrawcreate the same way? aren''t direct3d and directdraw combined into direct graphics or somethin? im using tricks of the windows game programming gurus to learn directx, and as long as i can do everything mostly the same way, then im happy.
thanx,
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
Well, your initialization code should be corrected in order to work. your call to lpdd->QueryInterface is not correct.The directdraw object is already initialized by a call to DirectDrawCreate. In fact the SDK doesn''t understand the IID_IDIRECTDRAW4 interface, possibly because it should not be used at all.(it''s not logical. you can''t call member functions of ddraw object if it is still not created. e.g :
LPDIRECTDRAW4 draw;
//draw is a pointer to a directdraw object
void init()
{draw->QueryInterface(IID_IDIRECTDRAW4,(LPVOID*)&ddraw );
// the error here is in the fact the ''draw'' pointer is null;
//so ddraw objects can''t be created this way.
//that''s why IID_IDIRECTDRAW4 interface doesn''t exist at all.
//(or is invisible to external applicatons)


}
All ddraw objects are created using DirectDrawCreate();
You probably confused it with a call
draw->QueryInterface(IID_IDIRECT3D4,(LPVOID*)&lp_d3d);


hope that helped

Share this post


Link to post
Share on other sites
yeah, the directX sdk''s are backwards compatible, so even though directdraw and direct3d are combined, you can still use directdraw seperately like you had an older compiler. I don''t know what the differences between DD7 and older versions are, it should mostly be the same.

__________________________________________
We get signal.
There are bombs exploding all around us!!

Share this post


Link to post
Share on other sites
grr im so frustrated right now i could kick something. *kicks chair* ow! well, i got the thingy to work kinda (using just LPDIRECTDRAW instead of LPDIRECTDRAW4) but i started actually making stuff (a primary surface, etc.) and it won''t recognize ANYTHING!! so i partially downloaded directx 8.0 (just the header files and libraries) and it STILL DOESN''T WORK!!! for the record, i had previously installed the full version Directx 6.1 SDK from the Tricks of the Windows... CD, and just replaced the old ddraw.h, ddraw.lib, dxguid.lib, etc... with the new dirextx 8.0 stuff. should i have done something else? the worst thing is, when i just let my mouse hover over LPDIRECTDRAW4, or 7, or whatever i''ve tried, it says typedef IDirectDraw# *LPDIRECTDRAW#, which lets me know that the libraries ARE being included/linked to (so wat''s the problem!?!?!) you can find the complete source code @ www.geocities.com/sega_dude101/main.txt plz take a look i''m going crazy tryin to figure this out.
thanx,
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
hey, you need to have the runtime version of dx8 installed in order for the SDK to work )). And if you have dx8 installed then libs and includes should be enough.
By the way, have you tried to correct your code as i advised in the previous page? if not then try.

Share this post


Link to post
Share on other sites
Maybe I can help...
If you put a line like this
  #define DIRECTDRAW_VERSION 0x0700  

in front of your
  #include <ddraw.h>  

it will tell the DirectDraw header file to compile properly for that version. The example above is for DirectDraw 7, and I don't know what number to use for DirectDraw 6, but I would try 0x0600.

I'm not really sure that this will help, though.

Edited by - TookH on August 19, 2001 4:19:40 PM

Share this post


Link to post
Share on other sites
hey, thanx all, but i found the solution! actually, the solution was a combination of things. i set the compiler to look in the C:\mssdk\include and \lib directories, but that was after it looked into the regular include and lib libraries (which i didn''t know had obsolete versions of the directx libraries and header files) so it used those instead. now, i''m gettin started on other stuff... but for some reason i''m having problem writing to the video buffer (when i try to, the program exits out almost immediatly. oh well... i guess another problem to figure out but i think i can debug that one for myself. again, thanx all!
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites