Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

linker error with vs2008

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

------ Build started: Project: dx test, Configuration: Debug Win32 ------ Linking... main.obj : error LNK2019: unresolved external symbol "long __cdecl d3d_int(struct HWND__ *,int,int,bool)" (?d3d_int@@YAJPAUHWND__@@HH_N@Z) referenced in function _WinMain@16 main.obj : error LNK2019: unresolved external symbol "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z) referenced in function _WinMain@16 H:\cpp\dx test\Debug\dx test.exe : fatal error LNK1120: 2 unresolved externals Build log was saved at "file://h:\cpp\dx test\dx test\Debug\BuildLog.htm" dx test - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I looked on google for an ansew for this but couldn't find one that worked. Ive tried stuff like adding "#pragma comment(lib,"user32.lib")" or setting WinMain as the entrry point in the linker properties but I still can't get it to compile... This is what I have so far... I created a new project named "dx test" (Empty Project) In Tools->Options->Projects and Solutions->VC++ Directories I added "D:\Microsoft DirectX SDK (November 2007)\Lib\x86" to the libary list and "D:\Microsoft DirectX SDK (November 2007)\Include" to the include list. In Project->dx test Properties...->Configuration Properties->General I set Checter Set to "Use Multi-Byte Charecter Set" Everything else is default. The source code:
#include <string>
#include <windows.h>
#include <d3D9.h>
#include <d3dx9.h>

IDirect3D9* pD3D9 = NULL;
IDirect3DDevice9* pD3DDevice9 = NULL;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

HRESULT d3d_int(HWND hwnd, int width, int height, bool fullscreen);
void d3d_destroy();
void Render();

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
	WNDCLASSEX windowClass;  // window class
	HWND hwnd = NULL;
	// fill out the window class structure
	windowClass.cbSize        = sizeof(WNDCLASSEX);
	windowClass.style         = CS_HREDRAW | CS_VREDRAW;
	windowClass.lpfnWndProc   = WindowProc;
	windowClass.cbClsExtra    = 0;
	windowClass.cbWndExtra    = 0;
	windowClass.hInstance     = hInstance;
	windowClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	windowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

	windowClass.lpszMenuName  = NULL;
	windowClass.lpszClassName = "window";
	windowClass.hIconSm       = LoadIcon(NULL, IDI_WINLOGO);

	// register the windows class
	if (!RegisterClassEx(&windowClass)) return 1;

	hwnd = CreateWindowEx(NULL, "window", "Simple Direct3D Program",
		0, 0, 400, 400,
		NULL, NULL, hInstance, NULL);

	 // check if window creation failed (hWND would equal NULL)
	if (!hwnd) return 1;
	if (FAILED(d3d_int(hwnd, 800, 600, false)))
		return 1;
	MSG msg;
	while (1)
		PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);

		if (msg.message == WM_QUIT) break;

	UnregisterClass("window", hInstance);
	return (msg.wParam);

HRESULT InitD3D(HWND hwnd, int width, int height, bool fullscreen)
	pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);
	if (pD3D9 == NULL) return E_FAIL;

	// get the display mode
	pD3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);

	// set the presentation parameters
	ZeroMemory(&d3dpp, sizeof(d3dpp));

	d3dpp.BackBufferWidth            = width;
	d3dpp.BackBufferHeight           = height;
	d3dpp.BackBufferCount            = 1;
	d3dpp.BackBufferFormat           = d3ddm.Format;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed                   = !fullscreen;
	d3dpp.EnableAutoDepthStencil     = true;
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D16;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	if (FAILED(pD3D9->CreateDevice(
		&d3dpp, &pD3DDevice9))) return E_FAIL;

	return S_OK;

void Render(void)
  pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET,
                     D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);


  // all of your rendering would go here


  pD3DDevice9->Present(NULL, NULL, NULL, NULL);

void d3d_destroy(void)
	if (pD3DDevice9)
		pD3DDevice9 = NULL;

	if (pD3D9)
		pD3D9 = NULL;

Share this post

Link to post
Share on other sites
You only declared those 2 functions, you never implemented them:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

HRESULT d3d_int(HWND hwnd, int width, int height, bool fullscreen);


Share this post

Link to post
Share on other sites
I should be more carful when coping stuff between files... Doesn't really help when the google results come up with stuff like changing the entry point or adding preproceesor things though...

Well thanks :) I think ive worked out what bit of the error says what function was missing.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!