获取ddsd.lPitch
qq:9611153 微信lgs9611153
时间:2009-12-11 04:58下午
所需资源:
Vc DirectDraw
从DirectDraw获取lPitch:
int GetSurfacelPitch(LPDIRECTDRAWSURFACE7 lpddsBack); int CDisplayHandle::GetSurfacelPitch(LPDIRECTDRAWSURFACE7 lpddsBack) { ATLASSERT (lpddsBack != NULL); LONG _lPitch = 0; HRESULT ddrval;
DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddrval = lpddsBack->Lock(NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);//经常发生失败的情况。 ATLASSERT (SUCCEEDED(ddrval)); if (FAILED(ddrval)) { if (ddrval == DDERR_INVALIDPARAMS) { ddrval = lpddsBack->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); } if (ddrval == DDERR_SURFACELOST) { lpddsBack->Restore(); ddrval = lpddsBack->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); } if (FAILED(ddrval)){ const TCHAR* chError = DXGetErrorString9(ddrval); CUtil::Instance()->DbgFilePrintf(L"TSClient",_T("TSPlayer::GetSurfacelPitch Backsurface Lock Failed,desc=%s."),chError); return -1; } } _lPitch = ddsd.lPitch;//一行字节数 lpddsBack->Unlock(NULL); CUtil::Instance()->DbgFilePrintf(L"TSClient",_T("TSPlayer: GetSurfacelPitch m_lPitch=%d."), _lPitch);
return _lPitch;// } |
补充:
不使用前次获取的m_lPitch,只需要在锁定的时候获取和判断即可。
int m_lPitch;//一行字节数
m_lPitch = -1;
m_lPitch = GetSurfacelPitch(m_lpddsBack);
替换为及时获取,避免首次获取失败。