Program from book is not working

This is a discussion on Program from book is not working within the Game Programming forums, part of the General Programming Boards category; I just began reading the book Beginning DirectX 10 Game Programming and when I tried to compile the program from ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    Question Program from book is not working

    I just began reading the book Beginning DirectX 10 Game Programming and when I tried to compile the program from the second chapter I get an array of error. Here are the first few

    Code:
    error: '__out' has not been declared
    error: expected ',' or '...' before '*' token
    error: '__in' has not been declared
    I have included the library file to my project and don't know what the problem is. Here is my code.

    Code:
    //Include the Windows header file, needed for all windows application'
    #include <windows.h>
    #include <tchar.h>
    #include <d3d10.h>
    #include <d3dx10.h>
    
    HINSTANCE hInst;
    HWND wndHandle;
    
    int width = 640;
    int height = 480;
    
    //Direct3D global variables
    ID3D10Device* pD3DDevice = NULL;
    IDXGISwapChain* pSwapChain = NULL;
    ID3D10RenderTargetView* pRenderTargetView = NULL;
    
    //Forward declarations
    bool InitWindow(HINSTANCE hInstance, int width, int height);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    //InitDirect3D
    bool InitDirect3D(HWND hWnd, int width, int height)
    {
        //Create and clear the DXGI_SWAP_CHAIN_DESC
        DXGI_SWAP_CHAIN_DESC swapChainDesc;
        ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
    
        //Fill in the needed values
        swapChainDesc.BufferCount = 1;
        swapChainDesc.BufferDesc.Width = width;
        swapChainDesc.BufferDesc.Height = height;
        swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
        swapChainDesc.BufferDesc.RefreshRate.Numerator = 1;
        swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
        swapChainDesc.OutputWindow = hWnd;
        swapChainDesc.SampleDesc.Count = 1;
        swapChainDesc.SampleDesc.Quality = 0;
        swapChainDesc.Windowed = TRUE;
    
        //Create the D3D device and the swap chain
        HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION,
                                                   &swapChainDesc, &pSwapChain, &pD3DDevice);
    
        //Error checking. Make sure the device context was created
        if(hr != S_OK)
        {
            return false;
        }
    
        //Get the back buffer from the swap chain
        ID3D10Texture2D *pBackBuffer;
        hr = pSwapChain->GetBuffer(0, _uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
        if(hr != S_OK)
        {
            return false;
        }
    
        //Create the render target view
        hr = pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView);
    
        //release the back buffer
        pBackBuffer->Release();
    
        //Make sure the render target view was created succesfuly
        if(hr != S_OK)
        {
            return false;
        }
    
        //Set the render target
        pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
    
        //Create and sett the viewport
        D3D10_VIEWPORT viewPort;
        viewPort.Width = width;
        viewPort.Height = height;
        viewPort.MinDepth = 0.0f;
        viewPort.MaxDepth = 1.0f;
        viewPort.TopLeftX = 0;
        viewPort.TopLeftY = 0;
        pD3DDevice->RSSetViewPort(1, &viewPort);
    
        return true;
    }
    
    //Render
    void Render()
    {
        if(pD3DDevice != NULL)
        {
            //Clear the target buffer
            pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
    
            //All the drawing will go here
    
            //display the next item in the swap chain
            pSwapChain->Present(0, 0);
        }
    }
    
    //SutdownDirect3D
    void ShutDownDirect3D()
    {
        //Release the renderTarget
        if(pRenderTargetView)
        {
            pRenderTargetView->Release();
        }
    
        //Release the swapchain
        if(pSwapChain)
        {
            pSwapChain->Release();
        }
    
        //Release the D3D Device
        if(pD3DDevice)
        {
            pD3DDevice->Release();
        }
    }
    
    //This si winmain, the main entry point for Windows Applications
    int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
    {
        //Initialize the window
        if(!InitWindow(hInstance, width, height))
        {
            return false;
        }
    
        if(!InitDirect3D(mainhWnd, width, height))
        {
            return 0;
        }
    
        //Main message loop
        MSG msg = {0};
        while(WM_QUIT != msg.message)
        {
            while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            //Call the render function
            Render();
        }
    
        ShutDownDirect3D();
    
        return (int)msg.wParam;
    }
    
    //Init window
    bool InitWindow(HINSTANCE hInstance, int width, int height)
    {
        WNDCLASSEX wcex;
    
        //Fill in the WNDCLASSEX structure. This describes how the window will look to the system
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc = (WNDPROC)WndProc;
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hInstance = hInstance;
        wcex.hIcon = 0;
        wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = TEXT("DirectXExample");
        wcex.hIconSm = 0;
        RegisterClassEx(&wcex);
    
        //Register the window
        RECT rect = { 0, 0, width, height};
        AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
    
        //Create the window from the class above
        wndHandle = CreateWindow(TEXT("DirectXExample"), TEXT("DirectXExample"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
                                 rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL);
    
        if(!wndHandle)
        {
            return false;
        }
    
        //Displays the window on the screen
        ShowWindow(wndHandle, SW_SHOW);
        UpdateWindow(wndHandle);
    
        return true;
    }
    
    //WndProc
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        //Check any available messages from the queue
        switch(message)
        {
            case WM_KEYDOWN:
              switch(wParam)
              {
                  //Check if the user hit the Escape key
                  case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;
              }
    
              //Always return the message to the default window procedure for further processing
              return DefWindowProc(hWnd, message, wParam, lParam);
        }
    }
    Thanks

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    _out and _in are not in the code you posted? What are the line numbers and filenames relating to the error? Do you get the error at the linking phase?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Quote Originally Posted by rogster001 View Post
    _out and _in are not in the code you posted? What are the line numbers and filenames relating to the error? Do you get the error at the linking phase?
    These errors where in the d3d10.h file and the error for _out was in line 818 and the one for _in was is line 822.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,624
    Quote Originally Posted by bijan311 View Post
    These errors where in the d3d10.h file and the error for _out was in line 818 and the one for _in was is line 822.
    There may be conflicting defines between <windows.h> and <d3d10.h>. Try changing the order of including them just in case.
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Quote Originally Posted by Sipher View Post
    There may be conflicting defines between <windows.h> and <d3d10.h>. Try changing the order of including them just in case.

    Nope, still not working

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reusing a 'deleted' record
    By spongefreddie in forum C Programming
    Replies: 16
    Last Post: 11-05-2010, 11:41 PM
  2. Program not working as expected
    By perrrson in forum C Programming
    Replies: 3
    Last Post: 10-02-2010, 01:49 PM
  3. Suggestions for my Check Book program
    By Nor in forum C++ Programming
    Replies: 2
    Last Post: 11-17-2008, 05:44 PM
  4. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  5. Program logic not working..
    By ronkane in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2002, 07:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21