Advertisement

[x]
Attachment Details

directx CreateDevice is giving a D3DERR_INVALIDCALL help!!

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2
I started programming a directx 3D graphics engine that runs in full screen, a couple months ago for a game I'm trying to make. I started programming and thought I finished the engine and started on the game.  
A month ago I moved to a new apartment, so I burnt and transferred all my files to a new computer. It still compiles just fine but I get a D3DERR_INVALIDCALL when I call the CreateDevice function. At first I thought there was something wrong with my computer so I played with compiling and running some of the directx example files, but they all worked fine.  So I must be doing something wrong in my code. Here is some of my code, keep in mind that the code is in a couple of different functions so the variable names might not line up:

// here is some header info
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <mmsystem.h>

#include <d3d8.h>
#include <d3dx8.h>
#include <dinput.h>
#include <stdio.h>
// Variables
LPDIRECT3D8 g_pD3D = 0;
LPDIRECT3DSURFACE8 g_pBackSurface = 0;
LPDIRECT3DVERTEXBUFFER8 g_pVB = 0;
LPDIRECT3DDEVICE8 g_pDevice= 0;
LPDIRECT3DINDEXBUFFER8 g_pIB=0;
LPDIRECT3DTEXTURE8 g_pTexture =0;
LPDIRECTINPUT8 g_pDI =0;

// here is where I setup the window I'm going to use.
      HWND hWnd;
      WNDCLASSEX wc;
      static char strAppName[]= GAME_NAME;

      wc.cbSize = sizeof(WNDCLASSEX);
      wc.style = CS_HREDRAW | CS_VREDRAW |CS_OWNDC;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.lpfnWndProc = WndProc;
      wc.hInstance = hInstance;
      wc.hbrBackground = (HBRUSH)GetStockObject( DKGRAY_BRUSH );
      wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor( NULL, IDC_CROSS);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = strAppName;
      
      RegisterClassEx( &wc);

      hWnd = CreateWindowEx(WS_EX_TOPMOST, strAppName, strAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 150, NULL, NULL, hInstance, NULL);
 
      hWndMain = hWnd;
            ShowWindow ( hWnd, iCmdShow);
            UpdateWindow (hWnd);
             return hWnd;
// this is my call to create the direct3d object
                g_pD3D =Direct3DCreate8( D3D_SDK_VERSION);

// and this is where I call the CreateDevice function
                                LPDIRECT3DDEVICE8 pDevice= 0;
            HRESULT r = 0;
            D3DDISPLAYMODE d3ddm;
            D3DPRESENT_PARAMETERS d3dpp;
            
            r=pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm);
            if ( FAILED(r) )
            {
                  SetError("Couldnot get display adapter information");
                  return NULL;
            }

            ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );

            d3dpp.BackBufferCount = 1;
            d3dpp.BackBufferWidth = 800;
            d3dpp.BackBufferHeight = 600;
            d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
            d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
            d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
            d3dpp.hDeviceWindow = hWndMain;
            d3dpp.Windowed = FALSE;
            d3dpp.EnableAutoDepthStencil = TRUE;
            d3dpp.AutoDepthStencilFormat =D3DFMT_D16;
            d3dpp.FullScreen_RefreshRateInHz = 0;
            d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
            d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
            
            r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndMain, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice);

            if ( FAILED(r))
            {
                                            char *MyMessage;
                                            if ( r == D3DERR_INVALIDCALL)
                                            {
                                                     MyMessage =new char[]=  "INVALIDCALL";
                                            } else if ( r==D3DERR_NOTAVAILABLE) {
                                                     MyMessage =new char[]=  "NOTAVAILABLE";
                                            } else if ( r==D3DERR_OUTOFVIDEOMEMORY) {
                                                     MyMessage =new char[]=  "OUTOFVIDEOMEMORY";
                                            }
                                            MessageBox(NULL,MyMessage,"Results", MB_YESNO);
                        SetError("Could not create the render device");
                        return NULL;
            }

That's it. I don't know what I'm doing wrong. I've been working on this for a couple days now. I’ve been striping the code down and trying different screen settings, but all give the same error. Any input would be greatly appreciated.

Thanks,
Minott
Related Solutions
Related Solutions
 
Loading Advertisement...
 
Accepted Solution by Maroy:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Expert Comment by TimDSmith:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Author Comment by Minott:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Expert Comment by Maroy:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Assisted Solution by TimDSmith:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Administrative Comment by AnnieMod:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Administrative Comment by AnnieMod:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
Loading Advertisement...
20080924-EE-VQP-40