DirectX Newb

This is a discussion on DirectX Newb within the Game Programming forums, part of the General Programming Boards category; I use MSVC++ 5.0, and I just got "Tricks of The Windwos Game Programming Gurus". I installed the DXSDK, and ...

  1. #1
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    DirectX Newb

    I use MSVC++ 5.0, and I just got "Tricks of The Windwos Game Programming Gurus". I installed the DXSDK, and i have directed MSVC++ to the lib/h files, but this code won't work:
    Code:
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    #include <ddraw.h>
    #define WIN32_LEAN_AND_MEAN
    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    int Game_Init();
    LPDIRECTDRAW7 lpdd7;
    HDC hdc;
    HWND hwnd;
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	PAINTSTRUCT ps;
    	switch(msg)
    	{
    	case WM_CREATE:
    		return 0;
    		break;
    	case WM_PAINT:
    		hdc = BeginPaint(hwnd,&ps);
    		EndPaint(hwnd,&ps);
    		break;
    	case WM_DESTROY:
    	case WM_CLOSE:
    		PostQuitMessage(0);
    		return 0;
    		break;
    	}
    	return (DefWindowProc(hwnd,msg,wParam,lParam));
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    				   LPSTR lpcmdline, int ncmdshow)
    {
    	WNDCLASSEX Window;
    	MSG msg;
    
    	Window.cbSize= sizeof(WNDCLASSEX);
    	Window.style= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
        Window.lpfnWndProc= WndProc;
        Window.cbClsExtra= 0;
        Window.cbWndExtra= 0;
        Window.hInstance= hInstance;						
        Window.hIcon= LoadIcon (NULL, IDI_WINLOGO);
        Window.hCursor= LoadCursor (NULL, IDC_ARROW);
        Window.hbrBackground= CreateSolidBrush(RGB(255,255,255));
        Window.lpszMenuName= NULL;
        Window.lpszClassName= "Window";			
        Window.hIconSm= LoadIcon (NULL, IDI_WINLOGO);	
    	
    	if (!RegisterClassEx(&Window)) return 0;
    
    	hwnd = CreateWindowEx(NULL,
    		"Window",
    		"First DirectX Program",
    		WS_OVERLAPPED | WS_VISIBLE,
    		0,0,640,480,
    		NULL,NULL,
    		hInstance,
    		NULL);
    	if (!(hwnd)) return 0;
    
    	while(1)
    	{
    		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    		{
    			if(msg.message==WM_QUIT)
    				break;
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    	lpdd7->Release();
    	lpdd7=NULL;
    	return(msg.wParam);
    }
    int Game_Init()
    {
    	LPDIRECTDRAW lpdd;
    	if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd, IID_IDirectDraw7, NULL)))
                    lpdd->Release();
    	lpdd=NULL;
    	return 0;
    }
    I get these errors:
    First.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16
    First.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7
    Debug/First DirectX Program.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    If you look at the book closer you will notice that he specifically states you must link with the correct libraries for your code to work.

    So if you link with the correct libs it should work. I forget all of the libs but just look at the book and it will tell you. I think its when he intros DirectDraw, not sure what chapter. He also talks about it early on when he tells you how to setup MSVC to work with DirectX.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Correct, you must link to the appropriate libraries for the code to work. I think the two important libraries are:

    ddraw.lib // for direct draw
    dxguid.lib // for GUID

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    118
    I just compiled it by just including the one ddraw.lib, but I did it with Borland 5.0. Just thought i'd let you know.
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  5. #5
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    Okay, I'll try the above. But this one is for anyone that has the book: What does <BG> mean??? I DONT KNOW!
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  2. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 12:16 PM
  3. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 06:16 PM
  4. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-24-2004, 11:49 PM
  5. DirectX errors (newb alert)
    By confuted in forum Game Programming
    Replies: 2
    Last Post: 07-19-2003, 09:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21