CreateDevice() returns D3DERR_INVALIDCALL



I have a dialog app where I'd like to have a control that is direct3d
rendered. So, when this control's window is created I call an
CreateDevice() as below. But, it always fails with the error code
D3DERR_INVALIDCALL (0x8876086c).
I've essentially stolen this function from the Directx9 (December 2006)
SDK vertex tutorial sample. The SDK tutorial works perfectly. Why does
the same code fail in my program? I assume it's because the whole
dialog window isn't Direct3D, just one control. Is there something
special I need to do to make this work?

(I have also tried using D3DDEVTYPE_REF as suggested to people
reporting a similar problem in other forums, but that doesn't seem to
make any difference.)

Thanks,
PaulH

HRESULT InitD3D()
{
// Create the D3D object.
if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
ATLTRACE( _T( "Failed to Init Direct3D\n" ) );
return E_FAIL;
}

// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp = { 0 };
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

// Create the D3DDevice
HRESULT hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
m_hWnd,

D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&m_pd3dDevice );
if( FAILED( hr ) )
{
ATLTRACE( _T( "Failed to create Direct3D device. %#08x\n"
), hr );
return E_FAIL;
}

// Device state would normally be set here
return S_OK;
};

/// Used to create the D3DDevice
LPDIRECT3D9 m_pD3D;

/// Our rendering device
LPDIRECT3DDEVICE9 m_pd3dDevice;

.



Relevant Pages

  • Re: Painting Optimization
    ... When the user drags another window over the control, ... But my recollection is that it doesn't do any optimizations with that; OnPaintstill winds up getting called for a simple invalidation. ... So, barring that kind of support, you're left rendering off-screen and then copying to the window any time the window needs to be redrawn. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Direct 3D & Pocket PC Question
    ... Direct3D Mobile is capable of rendering to a window. ... Does anyone know if it is possible to create a control that uses Direct3D ... I would like them to still be able to use normal Form ...
    (microsoft.public.pocketpc.developer)
  • Re: is DirectX a good choice for me ?
    ... >That rules out Direct3D right off! ... Direct3D drivers have accuracy tests that they must ... OpenGL has pbuffers that allow off screen rendering, ... >but you still must create a window to use either OpenGL or Direct3D. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: DWN, Vista Areo and the Desktop background
    ... The first is finding the background window or ... what about the other application that is rendering to it? ... at some point it goes into Direct3D). ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Tearing in Direct3D with TFT/LCD-Display
    ... I'm having problems with tearing while rendering a Direct3D-scene. ... I'm using Windows XP SP2 with DirectX 9.0c ... Enabled and disabled VSYNC for Direct3D (and yes, ... can see one half of the first frame, and the other half of the next frame, ...
    (microsoft.public.win32.programmer.directx.graphics)