Archived

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

Furious George

Errors linking DirectX 9.0 program.

Recommended Posts

Hi i''m having troubles getting my program to work. basically it compilers ok but when it gets to linking i get the following error msg. Linking... main.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4 Debug/testing.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have d3dx9.lib in project settings as well and the path is at the top in the tab. here is the source for the program. It is just supposed to open up a directx 9.0b window on the screen. thankyou all in advance. Furious George #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <d3dx9.h> LPDIRECT3D9 g_pd3d = NULL; LPDIRECT3DDEVICE9 g_pd3ddevice = NULL; HRESULT InitD3D(HWND hwnd) { if (NULL == (g_pd3d = Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; if (FAILED(g_pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3ddevice))) { return E_FAIL; } return S_OK; } VOID ShutdownD3D() { if (g_pd3ddevice != NULL) g_pd3ddevice->Release(); if (g_pd3d != NULL) g_pd3d->Release(); } VOID Render() { g_pd3ddevice->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0); if(SUCCEEDED(g_pd3ddevice->BeginScene())) { g_pd3ddevice->EndScene(); } g_pd3ddevice->Present(NULL, NULL, NULL, NULL); } LRESULT WINAPI MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_DESTROY: ShutdownD3D(); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wparam, lparam); } INT WINAPI WinMain( HINSTANCE hinstance, HINSTANCE, LPSTR, INT) { WNDCLASSEX windowclass = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgHandler, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "D3D Framework Tutorial", NULL}; RegisterClassEx(&windowclass); HWND hwnd = CreateWindow("D3D Framework Tutorial", "Introduction", WS_OVERLAPPEDWINDOW, 100, 100, 600, 600, GetDesktopWindow(), NULL, windowclass.hInstance, NULL); if (SUCCEEDED(InitD3D(hwnd))) { ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message!=WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else Render(); } } UnregisterClass("D3D Framework Tutorial",windowclass.hInstance); return 0; }

Share this post


Link to post
Share on other sites
thanks, that was the problem. lol. but the window doesn''t stay on the screen. i know i compiled a few other beginner display window programs and had the same problem. it shows up then poof it''s gone. could it be related to direct x display mode or something?

Share this post


Link to post
Share on other sites
You probably ought to put some debugging messages in after each function call. That will tell you where it''s failing. Also, assign the return value of the D3D functions to a variable so you can output the error code in case that''s what''s failing.

Share this post


Link to post
Share on other sites
Thanks for your help. i''ve isolated the problem to be the lines

if (FAILED(g_pd3d->CreateDevice(D3DADAPTER_DEFAULT, 3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3ddevice)))
{
return E_FAIL;
}

in the InitD3D function call. For some reason that isn''t working the way it should.

Ooops it was just that the mode wasn''t supported by my video card. thanks everyone

Furious George

Share this post


Link to post
Share on other sites