Jump to content
  • Advertisement
Sign in to follow this  
NecoSpes

DirectX Linker Problem

This topic is 4553 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 pretty new to DirectX... My error is a linker error: error LNK2019: unresolved external symbol _DirectDrawCreateEx@16 referenced in function "int __cdecl Game_Init(void)" (?Game_Init@@YAHXZ). I'm pretty sure that the error is not in the code because I have some source code and I get the same error as stated above. I'm going to have to assume that the error is because I haven't included some libraries? But it seems that I did- an image can show this better... Here's my code just in case:
#define WIN32_LEAN_AND_MEAN

#define INITGUID // make sure directX guids are included

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <iostream> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> 
#include <math.h>
#include <io.h>
#include <fcntl.h>
#include <ddraw.h>

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

#define WINDOW_CLASS "WINCLASS1"

int Game_Init();
int Game_Main();
int Game_Shutdown();

HWND main_window_handle;
LPDIRECTDRAW7 lpdd;


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

	switch(msg)
	{
	case WM_CREATE:
		{
			//Initialization
			return 0;
		}break;
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);
			EndPaint(hwnd, &ps);
			return 0;
		}break;
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}break;

	case WM_CLOSE:
		{
			int id = MessageBox(main_window_handle, "Do you really want to quit?", "Quit", MB_YESNO);
			if(id == IDYES)
				return (DefWindowProc(hwnd, msg, wparam, lparam));
			else
				return 0;
		}break;
	
	default:break;
	}

	

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

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

	winclass.cbClsExtra = 0;
	winclass.cbSize = sizeof(WNDCLASSEX);
	winclass.cbWndExtra = 0;
	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.hInstance = hinstance;
	winclass.lpfnWndProc = WindowProc;
	winclass.lpszClassName = WINDOW_CLASS;
	winclass.lpszMenuName = NULL;
	winclass.style = CS_OWNDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;

	if(!RegisterClassEx(&winclass))
		return 0;

	if(!(hwnd = CreateWindowEx(NULL,
								WINDOW_CLASS,
								"Whee",
								WS_OVERLAPPEDWINDOW | WS_VISIBLE,								
								0,0,
								400,400,
								NULL,
								NULL,
								hinstance,
								NULL)))
		return 0;
	
	main_window_handle = hwnd;

	Game_Init();

	while(true)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		Game_Main();
	}
	
	Game_Shutdown();

	return msg.wParam;
}

int Game_Init()
{
	if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd, IID_IDirectDraw7, NULL)))
		return 0;
	if(FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL)))
		return 0;
	return 1;
}
int Game_Main()
{
	if(KEYDOWN(VK_ESCAPE))
		SendMessage(main_window_handle, WM_CLOSE,0,0);
	return 1;
}
int Game_Shutdown()
{
	if (lpdd)
	{
		lpdd->Release();
		lpdd = NULL;
	}
	return 1;
}

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Did you add the path to those files to the Libraries search path? You can enter that globally (Tools->Options->Ummm, somewhere around there) or under the linker options for the project.

Share this post


Link to post
Share on other sites
Yep, I've done that already.


//Edit
It seems that I fixed it by changing the search path to the x86. What's the difference between x86 and x64?

[Edited by - NecoSpes on December 31, 2005 8:50:17 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by NecoSpes
Yep, I've done that already.
*snip image*

//Edit
It seems that I fixed it by changing the search path to the x86. What's the difference between x86 and x64?


The difference is the x64 is designed for Windows 64 Bit specifically. x86 is for 32 bit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!