MSVS Express problems

Started by
11 comments, last by shahrouhi 14 years, 1 month ago
Hey there, im kinda new to the forums so cut me some slack :D. I have been coding in other languages (Python, Lua, to name a few) for about 3 years now, and i read a university grade book on Win32 Console apps. I decided to read the tutorial at www.directxtutorial.com and see if i could get a bit of know how on the subject of Direct X, and game design. I downloaded MSVS Express 2008 (was using 2005, maybe that could be a problem?) and the DirectX SDK. All of the other examples (the Win32 ones from that site) have been working, however, when i try the FIRST DirectX one, it fails on the 3rd line
 #include <windows.h>
#include <windowsx.h>
#include <d3d10.h>
#include <d3dx10.h>

#pragma comment (lib, "d3d10.lib")
#pragma comment (lib, "d3dx10.lib")

ID3D10Device* device;
ID3D10RenderTargetView* rtv;
IDXGISwapChain* swapchain;

void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);

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


int 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 = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300, 300,
                          800, 600,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    initD3D(hWnd);


    MSG msg;

    while(TRUE)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if(msg.message == WM_QUIT)
                break;
        }

        render_frame();
    }

    cleanD3D();

    return msg.wParam;
}


LRESULT 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);
}


void initD3D(HWND hWnd)
{
    DXGI_SWAP_CHAIN_DESC scd;

    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    scd.BufferCount = 1;
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    scd.OutputWindow = hWnd;
    scd.SampleDesc.Count = 1;
    scd.SampleDesc.Quality = 0;
    scd.Windowed = TRUE;

    D3D10CreateDeviceAndSwapChain(NULL,
                                  D3D10_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  0,
                                  D3D10_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &device);


    ID3D10Texture2D* pBackBuffer;
    swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
    device->CreateRenderTargetView(pBackBuffer, NULL, &rtv);
    pBackBuffer->Release();

    device->OMSetRenderTargets(1, &rtv, NULL);


    D3D10_VIEWPORT viewport;

    ZeroMemory(&viewport, sizeof(D3D10_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = 800;
    viewport.Height = 600;

    device->RSSetViewports(1, &viewport);
}


void render_frame(void)
{
    device->ClearRenderTargetView(rtv, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    swapchain->Present(0, 0);
}


void cleanD3D(void)
{
    swapchain->Release();
    rtv->Release();
    device->Release();
}
It did have comments, but i took them out because its may have been part of the 'payed tutorial' and id rather not get in trouble. When i try and compile, i get this error
1>LINK : fatal error LNK1104: cannot open file 'd3dx10.lib'
I did include the Library folder, and the Header folder from the DirectX SDK, but maybe i did it wrong? I am so confused right now. And yes i did a search, but got nothing out of it :(
Advertisement
What library directory did you add to your project settings? All of the DirectX library files are found in both the "_SDK_\Lib\x86" and "_SDK_\Lib\x64" directories, where _SDK_ is the path to which you installed the DirectX SDK. You should add the one that's relevant to your system (x86 is for 32-bit).
Quote:Original post by Shadowflare
What library directory did you add to your project settings? All of the DirectX library files are found in both the "_SDK_\Lib\x86" and "_SDK_\Lib\x64" directories, where _SDK_ is the path to which you installed the DirectX SDK. You should add the one that's relevant to your system (x86 is for 32-bit).


Oh, Damn. I didn't even look in the lib folder, i just assumed it would be the same as the Include one (which i used as the Header's in MSVS).

And would that fix it? Because it was a problem with the include (might be a nice opertunity to mention that im using C++ if i didn't before)
Yes, it should.

Quote:
1>LINK : fatal error LNK1104: cannot open file 'd3dx10.lib'


Is this the only error you get? If so, adding the x86 or x64 directory to your additional library directories should fix your problem. If not, we'll just go one step at a time. :)
Quote:Original post by Shadowflare
Yes, it should.

Quote:
1>LINK : fatal error LNK1104: cannot open file 'd3dx10.lib'


Is this the only error you get? If so, adding the x86 or x64 directory to your additional library directories should fix your problem. If not, we'll just go one step at a time. :)


Holy crap, epic fail on my part. I totally read that as 'd3dx10.h'. Ill just test now.
I just tested and it work. You are my new favorite person :):)
Obligatory threads about directxtutorial.com:

Click 1, Click 2
Quote:Original post by mattd
Obligatory threads about directxtutorial.com:

Click 1, Click 2


Its good to know that. I think ill use the site as a way to learn how DirectX/DirectX functions work, rather than HOW to use them. Thanks for that :)
hi there
friends i've got the same error as MGinshe " got , i am using windows 7 32bit ,MVS2008 dxsdk feb2010. .
after 2weeks dealing with DXSDK & visual studio + several times changing my directx version and visual studio version , now i am facing with that problem 'can not open d3dx10.lib' and changing the liberary directory to 64 did not work again.

MGinshe " what you realy did with that prob?
Quote:I think ill use the site as a way to learn how DirectX/DirectX functions work

Make that, "partly how they work." An extremely important part of how D3DX functions work is returning a status code. That returned code should be checked for success or failure. For whatever reason, that site assumes the world is perfect and no errors ever occur.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement