   Problem Building DX Window
  I am looking at this thing here on a ebook of Beginning Game Programming and Starting D3D by making a window,Unfortunately I got this errors, how do i fix this ? D3dWindowed.obj : error LNK2019: unresolved external symbol "void __cdecl Game_End(struct HWND__ *)" (?Game_End@@YAXPAUHWND__@@@Z) referenced in function "long __stdcall WinProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WinProc@@YGJPAUHWND__@@IIJ@Z)D3dWindowed.obj : error LNK2019: unresolved external symbol __imp__GetStockObject@4 referenced in function "unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z)D3dWindowed.obj : error LNK2019: unresolved external symbol "void __cdecl Game_Run(struct HWND__ *)" (?Game_Run@@YAXPAUHWND__@@@Z) referenced in function _WinMain@16D3dWindowed.obj : error LNK2019: unresolved external symbol "int __cdecl Game_Init(struct HWND__ *)" (?Game_Init@@YAHPAUHWND__@@@Z) referenced in function _WinMain@16CODE:--------------------------------------------------------------------------------#include <d3d9.h> #include <time.h> //application title#define APPTITLE "Direct3D_Windowed"//forward declarationsLRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM);ATOM MyRegisterClass(HINSTANCE);int Game_Init(HWND); void Game_Run(HWND);  void Game_End(HWND); //Direct3D objects LPDIRECT3D9 d3d = NULL; LPDIRECT3DDEVICE9 d3ddev = NULL;//window event callback function LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {switch( msg ){    case WM_DESTROY:    Game_End(hWnd);  PostQuitMessage(0);  return 0;}return DefWindowProc( hWnd, msg, wParam, lParam ); } //helper function to set up the window properties ATOM MyRegisterClass(HINSTANCE hInstance) { //create the window class structureWNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX);//fill the struct with infowc.style= CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc    = (WNDPROC)WinProc; wc.cbClsExtra   = 0; wc.cbWndExtra   = 0; wc.hInstance = hInstance; wc.hIcon= NULL; wc.hCursor   = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName   = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm   = NULL;//set up the window with the class info    return RegisterClassEx(&wc);}//entry point for a Windows program    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTRlpCmdLine,int  nCmdShow){    // declare variables    MSG msg;    // register the class    MyRegisterClass(hInstance);    // initialize application    //note--got rid of initinstance    HWND hWnd; //create a new window    hWnd = CreateWindow( APPTITLE,  //window class APPTITLE,  //title bar WS_OVERLAPPEDWINDOW, //window style CW_USEDEFAULT,  //x position of window CW_USEDEFAULT,  //y position of window500,  //width of the window 400,  //height of the window NULL, //parent window NULL, //menu hInstance, //application instance NULL);//window parameters //was there an error creating the window?    if (!hWnd)  return FALSE;    //display the window    ShowWindow(hWnd, nCmdShow);  UpdateWindow(hWnd); //initialize the game   if (!Game_Init(hWnd))   return 0; // main message loop int done = 0; while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {//look for quit message if (msg.message == WM_QUIT) {MessageBox(hWnd, "Received WM_QUIT message", "WinMain", MB_OK);done = 1; }//decode and pass messages on to WndProcTranslateMessage(&msg;DispatchMessage(&msg; }   else   //process game loop (else prevents running after window is closed)   Game_Run(hWnd); }   return msg.wParam; }--------------------------------------------------------------------------------   
  It looks like you've forgot to include windows.h. Thats my guess.External symbols is often headers or libs missing./* ZuraK   ;  You need implementations of Game_Run, Game_Init and Game_End.. (you can just make the function bodies empty if you don't want to do anything in them to start with).The one for GetStockObject I don't know.. try fixing the others and see what happens.. it's supposed to be in Gdi32.lib according to MSDN, but it seems very strange for that not to be included while other Win32 functions work.   ;Quote:Original post by Erik RufeltThe one for GetStockObject I don't know.. try fixing the others and see what happens.. it's supposed to be in Gdi32.lib according to MSDN, but it seems very strange for that not to be included while other Win32 functions work.If he's using a MSVC 2005 Express Edition and had to manually install the platform SDK, then it's pretty easy to skip the step that automatically includes gdi32.lib in the linker options.   ;Quote:Original post by ZuraKIt looks like you've forgot to include windows.h. Thats my guess.External symbols is often headers or libs missing.No. A missing symbol at link time can never be the result of a missing header. A missing header would result in compile time errors - not link time errors.   ;  I have tried both options and it still gave me that errorEDIT: I Think the only problems for me is i get Unresolved External Symbol Errors and it saying source is in Mac Format its so frustrating that i cant get it to work, it looks like it gives that same error for all DX Code i try, could it be i didnt set up DX right for C++ ? i linked the libraries but could it be possible there is more i need to do ?WINAPI based code seems to work fine with me but DX related code just gives me those erros[Edited by - Cooljay on June 13, 2009 1:38:38 PM];Quote:Original post by SiCraneQuote:Original post by ZuraKIt looks like you've forgot to include windows.h. Thats my guess.External symbols is often headers or libs missing.No. A missing symbol at link time can never be the result of a missing header. A missing header would result in compile time errors - not link time errors.Ah! Thanks for clarification.   ;  Fixed it :D , had to Pragma the direct3d.libaryand add WIN32 LEAN AND MEAN   ;Quote:Original post by CooljayFixed it :D , had to Pragma the direct3d.libaryand add WIN32 LEAN AND MEANCongrats.As long as you know, neither of those were the actual solution to your problem :)   ;  yeah i got through that big trouble but it seems it caught up again with another problem i cant solve here when loading a .X fileERROR LOG///////////////////////////////////////////////////////////////////////e:\c++\vc\include\math.h(467) : warning C4067: unexpected tokens following preprocessor directive - expected a newlinee:\c++\vc\include\math.h(469) : error C2059: syntax error : '}'e:\c++\vc\include\math.h(469) : error C2143: syntax error : missing ';' before '}'e:\c++\vc\include\math.h(469) : error C2059: syntax error : '}'e:\c++\vc\include\math.h(471) : error C2143: syntax error : missing ';' before '{'e:\c++\vc\include\math.h(471) : error C2447: '{' : missing function header (old-style formal list?)e:\c++\vc\include\math.h(477) : error C2447: '{' : missing function header (old-style formal list?)CODE////////////////////////////////////////////////////////////////////////////// include the basic windows header files and the Direct3D header file#include <windows.h>#include <windowsx.h>#include <d3d9.h>#include <d3dx9.h>// define the screen resolution and keyboard macros#define SCREEN_WIDTH 640#define SCREEN_HEIGHT 480#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)// include the Direct3D Library files#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")// global declarationsLPDIRECT3D9 d3d;    // the pointer to our Direct3D interfaceLPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device classLPDIRECT3DVERTEXBUFFER9 t_buffer = NULL;    // the pointer to the vertex bufferLPDIRECT3DSURFACE9 z_buffer = NULL;    // the pointer to the z-buffer// mesh declarationsLPD3DXMESH meshBaretta;    // define the mesh pointerD3DMATERIAL9* material;    // define the material objectDWORD numMaterials;    // stores the number of materials in the mesh// function prototypesvoid initD3D(HWND hWnd);    // sets up and initializes Direct3Dvoid render_frame(void);    // renders a single framevoid cleanD3D(void);    // closes Direct3D and releases memoryvoid init_graphics(void);    // 3D declarationsvoid init_light(void);    // sets up the light and the material// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = (WNDPROC)WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);wc.lpszClassName = L"WindowClass1";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL, L"WindowClass1",  L"Our Direct3D Program", WS_EX_TOPMOST | WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);    // enter the main loop:    MSG msg;    while(TRUE)    {   DWORD starting_point = GetTickCount();   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  if (msg.message == WM_QUIT) break;  TranslateMessage(&msg;  DispatchMessage(&msg;   }   render_frame();   // check the 'escape' key   if(KEY_DOWN(VK_ESCAPE))  PostMessage(hWnd, WM_DESTROY, 0, 0);   while ((GetTickCount() - starting_point) < 25);    }    // clean up DirectX and COM    cleanD3D();    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {   case WM_DESTROY:  { PostQuitMessage(0); return 0;  } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}// this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    D3DPRESENT_PARAMETERS d3dpp;    ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.Windowed = FALSE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.hDeviceWindow = hWnd;    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    d3dpp.BackBufferWidth = SCREEN_WIDTH;    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    d3dpp.EnableAutoDepthStencil = TRUE;    // automatically run the z-buffer for us    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;    // 16-bit pixel format for the z-buffer    // create a device class using this information and the info from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL,  hWnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING,  &d3dpp,  &d3ddev);    init_graphics();    // call the function to initialize the triangle    init_light();    // call the function to initialize the light and material    d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);    // turn on the 3D lighting    d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer    d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));    // ambient light    return;}// this is the function used to render a single framevoid render_frame(void){    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->BeginScene();    // SET UP THE TRANSFORMS    D3DXMATRIX matView;    // the view transform matrix    D3DXMatrixLookAtLH(&matView,    &D3DXVECTOR3 (0.0f, 4.0f, 8.0f),    // the camera position    &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position    &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matViewD3DXMATRIX matProjection;    // the projection transform matrix    D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45),    // the horizontal field of view SCREEN_WIDTH / SCREEN_HEIGHT,    // the aspect ratio 1.0f,    // the near view-plane 100.0f);    // the far view-plane    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection    static float index = 0.0f; index+=0.03f;    // an ever-increasing float value    D3DXMATRIX matRotateY;    // a matrix to store the rotation for each triangle    D3DXMatrixRotationY(&matRotateY, index);    // the rotation matrix    d3ddev->SetTransform(D3DTS_WORLD, &(matRotateY));    // set the world transform    // draw the spaceship    for(DWORD i = 0; i < numMaterials; i++)    // loop through each subset    {   d3ddev->SetMaterial(&material);    // set the material for the subset   meshBaretta->DrawSubset(i);    // draw the subset    }    d3ddev->EndScene();d3ddev->Present(NULL, NULL, NULL, NULL);    return;}// this is the function that cleans up Direct3D and COMvoid cleanD3D(void){    meshBaretta->Release();    // close and release the spaceship mesh    d3ddev->Release();    // close and release the 3D device    d3d->Release();    // close and release Direct3D    return;}// this is the function that puts the 3D models into video RAMvoid init_graphics(void){    LPD3DXBUFFER bufShipMaterial;    D3DXLoadMeshFromX(L"Gun.x",    // load this file  D3DXMESH_SYSTEMMEM,    // load the mesh into system memory  d3ddev,    // the Direct3D Device  NULL,    // we aren't using adjacency  &bufShipMaterial,    // put the materials here  NULL,    // we aren't using effect instances  &numMaterials,    // the number of materials in this model  &meshBaretta);    // put the mesh here    // retrieve the pointer to the buffer containing the material information    D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufShipMaterial->GetBufferPointer();    // create a new material buffer for each material in the mesh    material = new D3DMATERIAL9[numMaterials];    for(DWORD i = 0; i < numMaterials; i++)    // for each material...    {   material = tempMaterials.MatD3D;    // get the material info   material.Ambient = material.Diffuse;    // make ambient the same as diffuse    }    return;}// this is the function that sets up the lights and materialsvoid init_light(void){    D3DLIGHT9 light;    // create the light struct    ZeroMemory(&light, sizeof(light));    // clear out the struct for use    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'    light.Diffuse.r = 0.5f;    // .5 red    light.Diffuse.g = 0.5f;    // .5 green    light.Diffuse.b = 0.5f;    // .5 blue    light.Diffuse.a = 1.0f;    // full alpha (we'll get to that soon)    D3DVECTOR vecDirection = {-1.0f, -0.3f, -1.0f};    // the direction of the light    light.Direction = vecDirection;    // set the direction    d3ddev->SetLight(0, &light);    // send the light struct properties to light #0    d3ddev->LightEnable(0, TRUE);    // turn on light #0    return;}