Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Direct help needed for directx newbie

crazygavcrazygav Member Posts: 8
Just a little script problem here ~ i get the following error msg when i try to build my very simple program (all it does is initialize direct3d and create plain blue window) I am a total newb to this so all help is appreciated and comments will be listened to however harsh!

here is the error i get while the program is linking
--------------------Configuration: Cpp2 - Win32 Debug--------------------
Linking...
Cpp2.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Cpp2.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.


Here is the problem source.

Cpp2.exe - 3 error(s), 0 warning(s)

#include
#include


///GLOBAL VARS:

LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;

//////////////////////////
///// Init D3D Object and device
/////
//////////////////////////

HRESULT D3DInit(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;


}

//////////////////////////////////////////////////////////////
//// RENDER()
///////////////////////////////////////////////////////////////

void Render()

{
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

g_pd3dDevice->BeginScene();





g_pd3dDevice->EndScene();
}

/////////////////////////////////////////////////////////////
//// DISPLAY() ~ after rendering you must display the stuff!/
/////////////////////////////////////////////////////////////

void Display()

{
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

//////////////////////////////
/////////// CLEANUP()
//////////////////////////////

VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}




//////////////////////////////////////////////////////////////
// MsgProc() Handler
//
/////////////////////////////////////////////////////////////////

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}

return DefWindowProc( hWnd, msg, wParam, lParam );
}


///////////////////////////////////////////////////////////////////
////////
//////// WINMAIN
////////
///////////////////////////////////////////////////////////////////

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class.
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL };

RegisterClassEx( &wc );

// Create the application's window.
HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 01: CreateDevice",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, wc.hInstance, NULL );

if (SUCCEEDED (D3DInit(hWnd)))
{

ShowWindow (hWnd, SW_SHOWDEFAULT);
UpdateWindow (hWnd);
}



MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}


UnregisterClass( "D3D Tutorial", wc.hInstance );
return 0;

}


Comments

  • chick80chick80 Member Posts: 349
    : Cpp2.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4
    : LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    : Debug/Cpp2.exe : fatal error LNK1120: 2 unresolved externals
    : Error executing link.exe.

    You forgot to link with d3d9.lib, that's why Direct3DCreate9 was not found. You should add the lib file to the linker options (how to do this depends on your compiler).
    As for the 2nd error (unresolved _main), perhaps you have created a console project, instead of a Win32 project, and so the program searches for main and not for WinMain.

    nICO


    [hr]
    [italic]How beautiful, if sorrow had not made Sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • crazygavcrazygav Member Posts: 8
    Thanks for the help. I made it into win32 app and added d3d9.lib to 'resources' folder... now onto the next problem... haha so much to learn!
Sign In or Register to comment.