Sign in to follow this  

header file not recognized... HELP!!!

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I posted earlier that I was having problems with this code... for some reason, the compiler I am using (Visual C++ 2005 Express edition) gives me this error: ------ Build started: Project: load_bitmap, Configuration: Debug Win32 ------ Compiling... winmain.cpp c:\users\ethan\c++ stuff\load_bitmap\winmain.cpp(6) : fatal error C1083: Cannot open include file: 'd3d9.h': No such file or directory Build log was saved at "file://c:\Users\Ethan\C++ Stuff\load_bitmap\Debug\BuildLog.htm" load_bitmap - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== I am unsure why it fails to recognize d3d9.h. I have the header file; it is in the Microsoft DirectX SDK (April 2006). Any help would be appreciated!!! Here is the full code, although I'm sure all of it isn't needed to determine the problem. It never hurts to be safe! Thanks for any help! // Beginning Game Programming, 2nd Edition // Chapter 6 // Load_Bitmap program //header files to include #include <d3d9.h> #include <d3dx9.h> #include <time.h> //application title #define APPTITLE "Create_Surface" //macros to read the keyboard asynchronously #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) //screen resolution #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 //forward declarations LRESULT 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; LPDIRECT3DSURFACE9 backbuffer = NULL; LPDIRECT3DSURFACE9 surface = 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 structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the struct with info wc.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, LPSTR lpCmdLine, 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_EX_TOPMOST | WS_VISIBLE | WS_POPUP, //window style CW_USEDEFAULT, //x position of window CW_USEDEFAULT, //y position of window SCREEN_WIDTH, //width of the window SCREEN_HEIGHT, //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) done = 1; //decode and pass messages on to WndProc TranslateMessage(&msg); DispatchMessage(&msg); } else //process game loop (else prevents running after window is closed) Game_Run(hWnd); } return msg.wParam; } int Game_Init(HWND hwnd) { HRESULT result; //initialize Direct3D d3d = Direct3DCreate9(D3D_SDK_VERSION); if (d3d == NULL) { MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK); return 0; } //set Direct3D presentation parameters D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3dpp.hDeviceWindow = hwnd; //create Direct3D device d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); if (d3ddev == NULL) { MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK); return 0; } //set random number seed srand(time(NULL)); //clear the backbuffer to black d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); //create surface result = d3ddev->CreateOffscreenPlainSurface( 640, //width of the surface 480, //height of the surface D3DFMT_X8R8G8B8, //surface format D3DPOOL_DEFAULT, //memory pool to use &surface, //pointer to the surface NULL); //reserved (always NULL) if (result != D3D_OK) return 1; //load surface from file into newly created surface result = D3DXLoadSurfaceFromFile( surface, //destination surface NULL, //destination palette NULL, //destination rectangle "legotron.bmp", //source filename NULL, //source rectangle D3DX_DEFAULT, //controls how image is filtered 0, //for transparency (0 for none) NULL); //source image info (usually NULL) //make sure file was loaded okay if (result != D3D_OK) return 1; //return okay return 1; } void Game_Run(HWND hwnd) { //make sure the Direct3D device is valid if (d3ddev == NULL) return; //start rendering if (d3ddev->BeginScene()) { //create pointer to the back buffer d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //draw surface to the backbuffer d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); //stop rendering d3ddev->EndScene(); } //display the back buffer on the screen d3ddev->Present(NULL, NULL, NULL, NULL); //check for escape key (to exit program) if (KEY_DOWN(VK_ESCAPE)) PostMessage(hwnd, WM_DESTROY, 0, 0); } void Game_End(HWND hwnd) { //free the surface surface->Release(); //release the Direct3D device if (d3ddev != NULL) d3ddev->Release(); //release the Direct3D object if (d3d != NULL) d3d->Release(); } Ok, no more code. Thanks again for any help at all!!!

Share this post


Link to post
Share on other sites
Hello,

When using the brackets (<>) when #including a file, MSVC++ looks in it's standard Include directory. If d3d9.h is not there, it will give you that error.

Either:

  • Insure d3d9.h and d3dx9.h are inside of this include directory, and their corresponding library files are inside of the lib\ directory...

    Program Files/Microsoft Visual Studio 8/VC/Include/
    Program Files/Microsoft Visual Studio 8/VC/Lib/

  • Or, Add them to additional include and library directories. To do this, Go to your project settings...

    Configuration Properties->C/C++->General Set Additional Include Directories to point the directory where d3d9.h resides;

    Configuration Properties->Linker->General Set Additional Library Directories to point the directory where d3d9.lib resides.

    Share this post


    Link to post
    Share on other sites
    ok, i posted the include files into VC like you said... but I'm not sure about the libraries. There are 2 folders where I can grab those from, one being X64, the other being X86. I'll try each, and see what happens.

    Share this post


    Link to post
    Share on other sites
    Ok, I think the files are being included, but I am still getting an error... here it is:

    ------ Build started: Project: load_bitmap, Configuration: Debug Win32 ------
    Compiling...
    winmain.cpp
    c:\program files\microsoft directx sdk (april 2006)\include\d3d9.h(40) : fatal error C1083: Cannot open include file: 'objbase.h': No such file or directory
    Build log was saved at "file://c:\Users\Ethan\C++ Stuff\load_bitmap\Debug\BuildLog.htm"
    load_bitmap - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I believe objbase.h is called by d3d9.h, but I can not find objbase.h anywhere. Any idea what is wrong?

    Share this post


    Link to post
    Share on other sites
    Hello,

    Did you install the Win32 PSDK? objbase.h is part of the Win32 SDK. By default, MSVC++ 2005 does not come with it. You can easily test if it has been installed correctly by #include <windows.h>.

    If you have not installed it yet, uninstall the DirectX SDK, and install the Win32 PSDK first. Download it HERE. Insure to follow all instructions properly.

    If it has already been installed, then the configurations are still not set correctly.

    ---

    Also, the first bullet is guaranteed to work as long as you have all prerequisites set up.

    Share this post


    Link to post
    Share on other sites
    ok, here was an error I got... downloaded the stuff you told me too, i had to get those 4 files, 2 headers and 2 libs, and email them to myself, then get them off the internet to use at school. anyway, i put those files in thier correct places after installing the thing you siad, and this is the error i got...

    --------------------Configuration: Load_Bitmap - Win32 Debug--------------------
    Compiling...
    winmain.cpp
    c:\program files\microsoft visual studio\vc98\include\d3d9.h(211) : fatal error C1083: Cannot open include file: 'd3d9types.h': No such file or directory
    Error executing cl.exe.

    Load_Bitmap.exe - 1 error(s), 0 warning(s)

    I am not sure what to do now... thanks for any help!

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by opiaboy
    ok, here was an error I got... downloaded the stuff you told me too, i had to get those 4 files, 2 headers and 2 libs, and email them to myself, then get them off the internet to use at school. anyway, i put those files in thier correct places after installing the thing you siad, and this is the error i got...

    --------------------Configuration: Load_Bitmap - Win32 Debug--------------------
    Compiling...
    winmain.cpp
    c:\program files\microsoft visual studio\vc98\include\d3d9.h(211) : fatal error C1083: Cannot open include file: 'd3d9types.h': No such file or directory
    Error executing cl.exe.

    Load_Bitmap.exe - 1 error(s), 0 warning(s)

    I am not sure what to do now... thanks for any help!


    What do you mean you "got those 4 files"? Actually, let me step back for a moment. Follow these instructions to correctly install the platform SDK. If you didn't install the SDK it won't work. It sounds like you didn't actually install the SDK so much as copy a couple files over. But the SDK has far more than a few files and a large chunk of them will be necessary as many files include many other files. So, to summarize: Actually install the SDK by following the directions I linked to. Hope that helps.

    Share this post


    Link to post
    Share on other sites
    I actually downloaded the platform sdk... i was talking about the directx sdk. I couldn't download the directx sdk, so I just sent the files I needed to myself, which were d3d9.h, d3dx9.h, d3d9.lib, and d3dx9.lib. Those were the files that I needed from the directx sdk. I put those 2 .h files in the header folder, and the 2 .lib files in the library folder, and the platform sdk was downloaded before I did that. So... what went wrong? lol... sorry for all this trouble!

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by opiaboy
    I actually downloaded the platform sdk... i was talking about the directx sdk. I couldn't download the directx sdk, so I just sent the files I needed to myself, which were d3d9.h, d3dx9.h, d3d9.lib, and d3dx9.lib. Those were the files that I needed from the directx sdk. I put those 2 .h files in the header folder, and the 2 .lib files in the library folder, and the platform sdk was downloaded before I did that. So... what went wrong? lol... sorry for all this trouble!


    Same thing. It's good to learn how to take something you learned from one situation and apply it to another. For instance I said "It sounds like you didn't actually install the SDK so much as copy a couple files over. But the SDK has far more than a few files and a large chunk of them will be necessary as many files include many other files." I said that about the Platform SDK, but it applies to all SDKs. The directX SDK header files include other header files that you didn't copy over.

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by opiaboy
    I actually downloaded the platform sdk... i was talking about the directx sdk. I couldn't download the directx sdk, so I just sent the files I needed to myself, which were d3d9.h, d3dx9.h, d3d9.lib, and d3dx9.lib. Those were the files that I needed from the directx sdk. I put those 2 .h files in the header folder, and the 2 .lib files in the library folder, and the platform sdk was downloaded before I did that. So... what went wrong? lol... sorry for all this trouble!
    Quote:
    Original post by opiaboy
    c:\program files\microsoft visual studio\vc98\include\d3d9.h(211) : fatal error C1083: Cannot open include file: 'd3d9types.h': No such file or directory

    The error refers to the file d3dtypes.h, which you have not copied over. As such, the file is missing.

    This is one of the other header files nobodynews has been referring to that are part of the DirectX SDK. All of the four files that you copied over references other header files. Installing the complete SDK will insure that all of the needed header files are of the latest versions, and will fix this error.

    Just copying over d3dtypes.h may not fix this problem either, as d3d9.h references alot of other header files that you probably do not have. This is why you need to properly install the DirectX SDK, and not just copy files over.

    Even after resolving all header file problems, you will run into object and library problems next, as other object files will reference incorrect or undefined symbols from within other object files.

    This is why you cannot just copy over library, object, and header files at random. You need to insure you have the entire SDK installed as all the parts of the SDK work together.

    Why are you unable to download the DirectX SDK? Do you receive any error?

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Crypter
    Why are you unable to download the DirectX SDK? Do you receive any error?


    From his last thread...

    Quote:

    ok, i have a problem. the computer I use at school has mvsC++ 6.0 on it, but I am unable to install the directx sdk that I want to use for game development at school. I can't ask my teacher, and I can't install the sdk unless I am the adminisstrator on the computer. is there some way I could use the files I need from the sdk? some external way I could download the files and use them? or some way I can override this administrative crap? thanks for any help/advice!


    Honestly, there's no easy way to do a manual install with no administrator privileges and get all of the necessary headers, libraries, and DLLs. If you keep copying one file at a time then trying to decipher from error messages what you need next, you'll be at it for a long long time.

    Share this post


    Link to post
    Share on other sites
    apparently I can't install it without administrative priveleges, which belong to my teacher. I shouldn't be posting about this any time soon though... I hvae fall break now. I may post back if it doesn't work on my laptop... thanks for all your help you guys, I know a bit more now! I'm looking forward to developing games now, lol.

    Share this post


    Link to post
    Share on other sites

    This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

    If you intended to correct an error in the post then please contact us.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this