CreateDevice failing

Started by
6 comments, last by jrosenthal 13 years, 9 months ago
Hi - I am new to this sight and looking for help.

I have a straight c++ unmanaged dll that creates a 3d teapot and rotates it in a frameless window.

that was a proof of concept and not working on the next stage. i have a c# app that calls an unmanaged cpp dll. All the drawing and manipulations of my 3d objects will be done in this dll including it owning the window.

In my prototype (all done on the same machine using VS10) the rendering works. In my next stage it fails on CreateDevice with a -2005530516 error (8876086C).

Question 1 - where can I find a listing of the errors?

question 2 - any ideas why this may not work?

Since the code runs on the computer it is not a graphic card/directX installation issue. I am obviously doing something wrong.

Here is the code - both CreateDevice calls fail

BOOL InitXX()
{
HRESULT hr = 0;
D3DPRESENT_PARAMETERS params = {0};
D3DDISPLAYMODE desktop = {0};

g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);

if (!g_pDirect3D)
return FALSE;

// Just use the current desktop display mode.
hr = g_pDirect3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &desktop);

if (FAILED(hr))
return FALSE;

// Setup Direct3D for windowed rendering.
params.BackBufferWidth = 0;
params.BackBufferHeight = 0;
params.BackBufferFormat = desktop.Format;
params.BackBufferCount = 1;
params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.MultiSampleQuality = 0;
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
params.hDeviceWindow = g_hWnd;
params.Windowed = TRUE;
params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D24S8;
params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
params.FullScreen_RefreshRateInHz = 0;
params.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;

// Most video cards should have no problems creating pure devices.
// HAL - Hardware Abstract Layer

// Try hardware vertex processing first
hr = g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,
&params, &g_pDevice);

// if it failsprocess vertices in software - SLOWER!!
if (FAILED(hr))
{
// Fall back to software vertex processing for less capable hardware.
hr = g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &params, &g_pDevice);
}

if (FAILED(hr))
return FALSE;
Advertisement
You can get a mostly human readable string from a DirectX HRESULT value via the DXGetErrorDescription() function. As for what's going wrong, are you using the DirectX debug runtime?
i believe so - DSetup.lib.
dxguid.lib
d3d9.lib
d3dx9.lib
winmm.lib

Thanks for the DXGetErrorDescription(hr)

I added it and get a link error - is this a hint to things to come? BTW I am using DX9
For DXGetErrorDescription() you need dxerr.lib. The debug runtime for DirectX is enabled by opening the DirectX control panel and switching from the retail version of the runtime to the debug version of the runtime. The DirectX control panel is usually found in the start menu area that gets added when you install the DirectX SDK.
Well, I did not change the control panel setting but the description comes back as:

char buf[2048];
sprintf(buf, "Error description: %s\n",DXGetErrorDescription(hr));


the value of buf is
+ buf 0x0012e810 "Error description: I"


since the version of the DX dll works in the initial app I would not think that that would be an issue
I think I may have given you the wrong impression about the debug runtime. The debug runtime won't screw up your app (well usually) instead using the debug runtime will print diagnostic information in your debugger that tells you potential problems that your program may have.

Also, if DXGetErrorDescription() shows only a single character that probably means that you're using a Unicode build, but you're passing the result to a narrow character function. Either switch your function to a wide character variant or use DXGetErrorDescriptionA() to specifically use the narrow character version.
The error I am getting is Invalid Call

The info from Debug DirectX was useful. I have not fixed it but I have a direction now. My hwnd was invalid. Thanks!!!

This topic is closed to new replies.

Advertisement