• Advertisement

Archived

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

Why won't DirectX work?!

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

Why won''t this work?
  
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <ddraw.h>

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

HWND global_hwnd = NULL;

LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAW lpdd4 = NULL;

if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
{	
}

if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4)))
{
}

lpdd->Release();
lpdd = NULL;

HRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch(msg)
	{
	case WM_CREATE:
		{
			return(0);
		}break;

	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);
			EndPaint(hwnd, &ps);
			return(0);
		}break;

	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return(0);
		}break;
	
	default:break;

	}

	return(DefWindowProc(hwnd, msg, wparam, lparam));

}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
	WNDCLASSEX winclass;
	HWND hwnd;
	MSG msg;

	winclass.cbSize = sizeof(WNDCLASSEX);
	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_VREDRAW | CS_HREDRAW;

	winclass.lpfnWndProc = WinProc;
	winclass.hInstance = hinstance;
	winclass.cbClsExtra = NULL;
	winclass.cbWndExtra = NULL;
	winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	winclass.lpszClassName = "Winclass1";
	winclass.lpszMenuName = NULL;
	
	if(!(RegisterClassEx(&winclass)))
		return(0);

	if(!(hwnd = CreateWindowEx(NULL,
					"Winclass1",
					"My First Ecounter with DirectX!",
					WS_OVERLAPPEDWINDOW | WS_VISIBLE,
					0,0,
					700,700,
					NULL,
					NULL,
					hinstance,
					NULL)))

					return(0);

	while(1)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	
		if(KEYDOWN(VK_ESCAPE))
			SendMessage(hwnd, WM_CLOSE, 0 , 0);
	
	}

	return(msg.wParam);

}
  
Here are the errors: Compiling... Main.cpp C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(13) : error C2143: syntax error : missing '';'' before ''if'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(14) : error C2143: syntax error : missing '';'' before ''{'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(14) : error C2447: missing function header (old-style formal list?) C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(17) : error C2143: syntax error : missing '';'' before ''if'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(18) : error C2143: syntax error : missing '';'' before ''{'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(18) : error C2447: missing function header (old-style formal list?) C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(21) : error C2143: syntax error : missing '';'' before ''->'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(21) : error C2501: ''lpdd'' : missing storage-class or type specifiers C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(21) : error C2040: ''lpdd'' : ''int'' differs in levels of indirection from ''struct IDirectDraw *'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(21) : error C2143: syntax error : missing '';'' before ''->'' C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(22) : error C2501: ''lpdd'' : missing storage-class or type specifiers C:\Program Files\Microsoft Visual Studio\DirectX\FirstEcounter\Main.cpp(22) : error C2040: ''lpdd'' : ''int'' differs in levels of indirection from ''struct IDirectDraw *'' Error executing cl.exe. Main.obj - 12 error(s), 0 warning(s)
Take it to the Xtreme!

Share this post


Link to post
Share on other sites
Advertisement
a. Your errors have nothing to do with DX.
b. That''s Encounter.
c. Code must be put inside functions.
d. You really should learn the language (C++), your compiler (VC), and in particular understand error messages produced before attempting to program DX or any other API for that matter.
e. Stop copy-pasting code. How many lines of your program do you understand?

Share this post


Link to post
Share on other sites
add the line: #include "d3d.h" to the top (or whatever the header file for DX7 is)

Share this post


Link to post
Share on other sites
You should buy a good book about Windows programming. I recommend "Programming Windows" by Charles Petzold or "Windows 98 programming from the ground up" by Herbert Schildt.

Those books will teach you these things. You should understand basic win32 before atempting DX.

Share this post


Link to post
Share on other sites
This site teaches basic Win32 programming (I still recommend a book).

http://www.winprog.org/tutorial/

Share this post


Link to post
Share on other sites
hi!
where do you find tut''s with that Win2_lean_and_mean stuff in it?
cos i cant find any good ones on win32!

_________________________________________________________________________
Can someone be nice and help me on my way to be the next Hideo Kojima?
Thought So...

Share this post


Link to post
Share on other sites
quote:
Original post by granat
I recommend ... "Windows 98 programming from the ground up" by Herbert Schildt.


I second that. It makes a pretty good reference and teaches you anything you want to know about windows programming, and I do mean just about anything!



Moe''s site

Share this post


Link to post
Share on other sites
I''ve been over that tutorial many times. Well, I got it the DirectX to work a bit. Now it''s down to 2 link errors. I have the build directories set correctly and I know because I tested it. Also, the compiler seems not to care if I use:

LPDIRECTDRAW4 lpdd4 = NULL;

or

LPDIRECTDRAW lppd4 = NULL;

Which one''s correct?

Link errors:

Main.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw4
Debug/FirstEcounter.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


Take it to the Xtreme!


Share this post


Link to post
Share on other sites
I can''t debug without it linking successfully anyways!


Take it to the Xtreme!


Share this post


Link to post
Share on other sites
I''m not going to answer that, but this link will:

http://www.gamedev.net/community/forums/search.asp

Share this post


Link to post
Share on other sites
quote:
Main.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw4
Debug/FirstEcounter.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.



Try adding DXGUID.LIB to the library list in the linker options. That should fix a lot of link errors relating to IID_whatever. Also did you add DDRAW.LIB to the list as well if you don''t you''ll have even more headaches if you try to use DirecDrawCreate()

Share this post


Link to post
Share on other sites
Thanks master_ball, I found that I needed dxguid.lib.


Take it to the Xtreme!


Share this post


Link to post
Share on other sites
Thanks to Dan also. He posted it right before I had a chance to post my post.


Take it to the Xtreme!


Share this post


Link to post
Share on other sites

  • Advertisement