Kent Gell
Kent Gell

Reputation: 121

D3D Device Failure During Screen Locked

I have a problem caused by a failure in Direct3D9::CreateDevice(). It fails when the following code is executed with a locked screen under Windows 7. Due to requirements, I need to be able to create a device while the screen is locked.

I get a D3DERR_INVALIDCALL error when CreateDevice is called with the following parameters. I've experimented extensively with the HWND being used, and double checked that it is valid. I've also tried out various tweaks to the presentation parameters to no avail. Anyone encountered this before or have a better idea of what might be causing the invalid call return?

Again, this failure only occurs with a locked screen, when run in any other tested state, it succeeds.

D3DPRESENT_PARAMETERS pp;
ZeroMemory( &pp, sizeof(D3DPRESENT_PARAMETERS) );
pp.BackBufferFormat = D3DFMT_UNKNOWN;
pp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
pp.Windowed         = TRUE;

HWND focusWndHnd = GetConsoleWindow();

if ( focusWndHnd == NULL && pp.hDeviceWindow == NULL )
{
   focusWndHnd = ::GetDesktopWindow();
}


IDirect3DDevice9* pd3dDevice;

IDirect3D9* pD3D = Direct3DCreate9( D3D_SDK_VERSION );

hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, focusWndHnd,
             D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE, &pp, &pd3dDevice );

Upvotes: 12

Views: 2220

Answers (4)

Peter Rawytsch
Peter Rawytsch

Reputation: 125

Thanks to Chuck Walbourn's answer I have solved my related issue that the D3D Device initialization fails as soon the elevation prompt secure session is active. In my case I received a D3DERR_NOTAVAILABLE error during the secure session. Having replaced IDirect3D9* with IDirect3D9Ex* and Direct3DCreate9 with Direct3DCreate9Ex then initialization finished successfully!

Additionally I have to stress that Chuck's answer does not refer to Kent's answer directly but just to a related issue, since - as I have understood it right - Kent's scenario refers to the WTS_SESSIONSTATE_LOCK session that can be entered through CTRL+L. In Kent's case I haven't experienced a problem with the D3D initialization in a locked session.

Upvotes: 0

Chuck Walbourn
Chuck Walbourn

Reputation: 41077

The legacy Direct3D 9 interface considers the 'secure desktop' to be a lost device scenario. Use of a WDDM aware version of Direct3D (Direct3D9Ex, Direct3D 10.x, or Direct3D 11.x) will avoid this problem.

Upvotes: 3

Alban Lusitanae
Alban Lusitanae

Reputation: 235

Could it be that you need a different value for BackBufferFormat different than D3DFMT_UNKNOWN, due to only windowed apps allowing that value, just like OJ stated here?

Upvotes: 1

selbie
selbie

Reputation: 104559

My memory is hazy, but I believe this is a known limitation ("by design") with D3D with respect to the lock screen (and running as a service).

Even if you could create the D3D device, you won't be able to draw on top of the lock screen. So you'll probably be better off designing your app such that it defers the D3D device creation until after the screen becomes unlocked.

Use WTSRegisterSessionNotification to register for notifications of when the screen becomes locked or unlocked.

Upvotes: 0

Related Questions