ERROR DRIVING ME INSANE

Started by
24 comments, last by PhlashStudios 18 years, 8 months ago
hello,i have been doing windows and c++ programming for some time and hav just started using directx with microsoft visual studio .net 2003. i have the directx crap installed but whenever i try to run this program: /**************************************************************** * example2 * shows the user how to setup a windowed directx application * which clears the window to a blue color ****************************************************************/ #include <windows.h> // include directx9 #include <d3d9.h> // global variables HINSTANCE hInst; // application instance HWND wndHandle; // application window handle LPDIRECT3D9 pD3D; // the Direct3D Object LPDIRECT3DDEVICE9 pd3dDevice; // the Direct3D Device ////////////////////////////////////////////// forward declarations bool initWindow(HINSTANCE hInstance); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // DirectX functions bool initDirect3D(); void render(void); /********************************************************************* * WinMain *********************************************************************/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { if (!initWindow(hInstance)) { MessageBox(NULL, "Unable to create window", "ERROR", MB_OK); return false; } if (!initDirect3D()) { MessageBox(NULL, "Unable to init Direct3D", "ERROR", MB_OK); return false; } // Main message loop: 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(); } } // release the device and the direct3D object if( pd3dDevice != NULL) pd3dDevice->Release(); if( pD3D != NULL) pD3D->Release(); return (int) msg.wParam; } /********************************************************************* * initWindow *********************************************************************/ bool initWindow(HINSTANCE hInstance) { WNDCLASSEX wcex; 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 = "DirectXExample"; wcex.hIconSm = 0; RegisterClassEx(&wcex); // create the window wndHandle = CreateWindow("DirectXExample", "DirectXExample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL); if (!wndHandle) return false; ShowWindow(wndHandle, SW_SHOW); UpdateWindow(wndHandle); return true; } /********************************************************************* * WndProc *********************************************************************/ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } /********************************************************************* * initDirect3D * initializes direct3D *********************************************************************/ bool initDirect3D() { pD3D = NULL; pd3dDevice = NULL; // create the directX object if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) { return false; } // fill the presentation parameters structure D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 1; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferWidth = 640; d3dpp.hDeviceWindow = wndHandle; // create a default directx device if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wndHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) ) { return false; } return true; } /********************************************************************* * render *********************************************************************/ void render(void) { // check to make sure we have a valid Direct3D Device if( NULL == pd3dDevice ) return; // Clear the backbuffer to a blue color pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Present the backbuffer contents to the display pd3dDevice->Present( NULL, NULL, NULL, NULL ); } i get this error: LINK : fatal error LNK1104: cannot open file 'd3d9.lib' i have linked all the libraries and crap and have spent a lot of time on it and can't seem to figure out what the problem is. Can anybody help me?
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>
Advertisement
You probably didn't set the path to the D3D libs.
Yes I did in in the project properties under linker
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>
It can't find the link library. My first guess is that the path to the SDK lib directory hasn't been added to the IDE search path.

On VC6 it's under the Tools Menu, then Options -> Directories.

Presumably you've added the includes since it seems to find them without a problem. Adding libraries is basically the same thing.
Stay Casual,KenDrunken Hyena
Tried that already
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>
Quote:Original post by PhlashStudios
Yes I did in in the project properties under linker


Double check that it did get added, also go to the directory you've added and verify that d3d9.lib is indeed there.
Stay Casual,KenDrunken Hyena
When I added the directory, i didnt set a path, merely d3d9.lib, should I do the whole c:\ blah blah blah
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>
Try adding this to the top of you file:

#pragma comment(lib, "<put path to D3D libs folder here>\d3d9.lib")

When you put in the directory, you should ONLY put the path. That way when you say d3d9.lib, it knows where to look for it.
Quote:Original post by PhlashStudios
When I added the directory, i didnt set a path, merely d3d9.lib, should I do the whole c:\ blah blah blah


Yes, when you add the directory make sure it's an absolute path.
Stay Casual,KenDrunken Hyena
When I do that I get the same error message plus a couple of others
they are all pretty much like this:
warning C4129: 'd' : unrecognized character escape sequence
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>

This topic is closed to new replies.

Advertisement