Sign in to follow this  
sainimu78

Why to Lock the primary surface fail in this way

Recommended Posts

		HRESULT hr;
		HDC hDc;
		IDirectDraw7* pDDraw;
		DDSURFACEDESC2 dDrawSurfDesc={0};
		LPDIRECTDRAWSURFACE7 pDDrawSurf;
		LPDIRECTDRAWSURFACE7 pDDrawBcak;
		DDSCAPS2 ddscaps = {0};


		hr = DirectDrawCreateEx(NULL, (LPVOID*)&pDDraw, IID_IDirectDraw7, NULL);
		hr = pDDraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL);//DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
		//hr = pDDraw->SetDisplayMode(100, 100, 24, 0, 0);
		/*
		RECT rc;
		GetWindowRect(hWnd, &rc);
		SetWindowPos(hWnd, 0, rc.left, rc.top, rc.left+200, rc.top+200, 0);
		*/
		dDrawSurfDesc.dwSize = sizeof(dDrawSurfDesc);
		dDrawSurfDesc.dwFlags = DDSD_CAPS;
		dDrawSurfDesc.ddsCaps.dwCaps =  DDSCAPS_PRIMARYSURFACE;
		hr = pDDraw->CreateSurface(&dDrawSurfDesc, &pDDrawSurf, NULL); 
		hr = pDDrawSurf->Lock(NULL, &dDrawSurfDesc, DDLOCK_SURFACEMEMORYPTR, NULL);

An error occurs at the last line. the error code is "0x887601b3 ". I don't know how to fix it 

 

How to lock the primary surface? 

Share this post


Link to post
Share on other sites

HRESULT: 0x887601b3 (2289435059)
Name: DDERR_CANTLOCKSURFACE
Description: Access to this surface is being refused because no driver exists which can supply a pointer to the surface. This is most likely to happen when attempting to lock the primary surface when no DCI provider is present. Will also happen on attempts to lock an optimized surface.
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x01b3 (435)

 

I believe that you can't effectively lock the primary surface on modern drivers and Windows versions.

 

A workaround is to create a secondary frame buffer (or a back buffer), lock and manipulate it, and copy or flip it to the front buffer.

Share this post


Link to post
Share on other sites

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