-
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.
-
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.
-
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
-
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.
-
Okay, I'll try the above. But this one is for anyone that has the book: What does <BG> mean??? I DONT KNOW!:confused: :confused: :confused: :confused: