Jump to content
  • Advertisement

Archived

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

Fredric

Newbie DirectX Initialization Question

This topic is 6930 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 new to DirectX, and I''m having a few problems. I''ve made a very simple program that brings up a window, and hands over all the control to DirectDraw using lpdd->SetCooperativeLevel() (which is irrelevant to my problem..) Anyhow, I think I might be missing some type of an include. I get two errors that say that QueryInterface() and IID_IDirectDraw() haven''t been declared. I thought I included those two in ddraw.h and ddraw.lib? Anyhow, below is the chunk of code that brings up the errors: if(FAILED(QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4))) { MessageBox(hwnd, "Error! DDRAW: lpdd4", "Error", MB_OK); return 0; } Basically what that does, is I ask the interface for DirectDraw4.0, and if it fails, bring up a message box that says so. Anyhow... how come it''s saying that QueryInterface and IID_IDirectDraw4 haven''t been declared? I linked the compiler to ddraw.lib, and include the following in my app: #include "ddraw.h" #include "windows.h" Can anyone help? Thanks in advance GO LEAFS GO!

Share this post


Link to post
Share on other sites
Advertisement
You forgot that QueryInterface is a function from the IDirectDraw interface. Basically,
it's


if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4)))
{
MessageBox(hwnd, "Error! DDRAW: lpdd4", "Error", MB_OK);
return 0;
}


And duh, make sure that you had created lpdd beforehand, and I release lpdd right after I query for the new interface. That should fix your problem.

-Edit- Made a slight typo-

Trigon



I like food.

Edited by - TrigonLoki on 5/1/00 10:35:38 PM

Share this post


Link to post
Share on other sites
TrigonLoki - Thanks for the help, but one problem still occurs. When I compiled the app again, it sais that IID_IDirectDraw4 hasn''t be declared. How can I fix that? You were able to bog me down to 1 error, and that error that you fixed was simply putting the lpdd-> in front of Query Interface..

yes, I have already declared the lpdd''s, AND released them. To declare them I did:
LPDIRECTDRAW lpdd;
LPDIRECTDRAW lpdd4;

And I DID in fact already have it release the handle to DirectDraw when the app was ready to shut down by:
lpdd4->Release();
lpdd4 = NULL;

But, there is still one error: IID_IDirectDraw is an undeclared unidentifier.. what else did I miss?

GO LEAFS GO!

Share this post


Link to post
Share on other sites
Hi,

Did you remember to add the dxsdk include and lib directories to you compilers include and lib options?
Also remember that the folders have to be at the first position in that directory list.

Another thing is that if you want to use the DirectX 7.0 interface for example you have to declare you lpDD like this.

LPDIRECTDRAW7 lpDD; (notice the ''7'')

The same with the 4.0 interface that it seems that you want to use.

LPDIRECTDRAW4 lpDD; (and not just LPDIRECTDRAW)

Share this post


Link to post
Share on other sites
Jesava - you don''t need to have the DXSDK, but yes, I did link it to ddraw.lib, as I mentioned above.

when I put LPDIRECTDRAW4 lpdd4 = NULL; (put the 4 after the type), I compiled it. This time, it brough up 3 new errors! These are the errors I get when I change LPDIRECTDRAW lpdd4 = NULL; to LPDIRECTDRAW 4 lpdd4 = NULL; :

WinX.cpp(26) : error C2146: syntax error : missing '';'' before identifier ''lpdd4''
WinX.cpp(26) : error C2501: ''LPDIRECTDRAW4'' : missing storage-class or type specifiers
WinX.cpp(26) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Anyone else?

GO LEAFS GO!

Share this post


Link to post
Share on other sites
Oh well I ment the headers and lib files FROM the sdk I know you do not need the whole 128mb sdk
Anyway aer you 100% sure that you added those directories to the top of the list?? that is very important...

Share this post


Link to post
Share on other sites
You also have to include dxguid.lib in your project as well as ddraw.lib. I had the same problem yesterday with it not liking IID_IDirectDraw7, but it worked after I included dxguid.lib .

We shall be free; th'' Almighty hath not build here for his ervy, will not drive us hence: Here we may reign secure and in my choyce To reign is worth ambition though in Hell: Better to reign in Hell, than serve in Heav''n.

Share this post


Link to post
Share on other sites
You also have to include dxguid.lib in your project as well as ddraw.lib. I had the same problem yesterday with it not liking IID_IDirectDraw7, but it worked after I included dxguid.lib . Hope that helps.

We shall be free; th'' Almighty hath not build here for his ervy, will not drive us hence: Here we may reign secure and in my choyce To reign is worth ambition though in Hell: Better to reign in Hell, than serve in Heav''n.

Share this post


Link to post
Share on other sites
I added dxguid.lib to the project- but alas, that did not change anything. Here it is, the FULL code.. I hope you generous people can help me from there...
// a WinX game console

#include ''ddraw.h'' // include directdraw
#include ''windows.h'' // include important windows stuff

LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);

HWND hwnd;
int GameInit();
int Game_Shutdown();

LPDIRECTDRAW lpdd = NULL; // DDraw 1.0
LPDIRECTDRAW lpdd4 = NULL;

char szWinName[] = "MyWin"; // name of window class

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
WNDCLASSEX wcl;
MSG msg;

// define the window class
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WinProc;
wcl.style = 0;

wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = NULL;
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);

wcl.lpszMenuName = NULL; // no menu
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hInstance = hThisInstance;

// make the background of the window black
wcl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
// register the window class
if(!RegisterClassEx(&wcl)) return 0; // if the class doesn''t register, break it

// the window has been defined and registered,
// but now it''s time to create it
hwnd = CreateWindow(szWinName, // name of window class
"Windows Skeleton", //title
WS_OVERLAPPEDWINDOW, //style
CW_USEDEFAULT, // x
CW_USEDEFAULT, // y
CW_USEDEFAULT, // width
CW_USEDEFAULT, // height
NULL, // no parent window
NULL, // no menu
hThisInstance, //instance handle
NULL // no additional arguments
);

// diplay the window
GameInit();
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);

// create a message loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Game_Shutdown();
return msg.wParam;
}

// the message handler
LRESULT CALLBACK WinProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message){
case WM_DESTROY: // terminate the program
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

int GameInit()
{
if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
{
// return 0
MessageBox(hwnd, "Error! DDRAW: lpdd", "Error", MB_OK);
return 0;
}
if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4)))
{
MessageBox(hwnd, "Error! DDRAW: lpdd4", "Error", MB_OK);
return 0;
}

lpdd4->SetCooperativeLevel(hwnd, DDSCL_NORMAL);

return 1;
} // end GameInit

int Game_Shutdown()
{
if(lpdd4)
{
lpdd4->Release();
lpdd4 = NULL; // just to be safe!
} // end if
return 1;
}


GO LEAFS GO!

Share this post


Link to post
Share on other sites
I hope you''ve added the libraries/headers to your project (in Tools->options if you''re using vc++), and MAKE sure to move them to the top. IID_IDirectDraw is included by default, and you have to override that.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!