   D3DXLoadSurfaceFromMemory fail
int width  = 400;int heigth = 600;main(){// create windowWindow win(width, heigth);   // create IDirect3DDevice9 D3DDevice d3d( win.createWindow(0) ,width, heigth);d3d.create();   // abbrIDirect3DDevice9 *d = d3d.device();   // create a offscreen surface   IDirect3DSurface9 * offscreen;HRESULT hr_offset = d->CreateOffscreenPlainSurface(width, heigth, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &offscreen, 0);if(FAILED(hr_offset)){MessageBox(0,"offscreen fail",0,0);}// read file to memory that 4 byte for a pixelstd::ifstream ifs("400x600inarray.binary", std::ios_base::binary | std::ios_base::out);DWORD * pl = new DWORD[width * heigth];ifs.read((char*)pl, width * heigth * 4);ifs.close();// load to surface  . fail here HRESULT hr_load = D3DXLoadSurfaceFromMemory(offscreen, 0, 0, pl, D3DFMT_X8R8G8B8, width * 4, 0, 0, D3DX_FILTER_NONE, 0xff000000);if(FAILED(hr_load)){MessageBox(0,"fail to load",0,0);}   // look d->Present(0,0,0,0);}D3DXLoadSurfaceFromMemory fail with D3DERR_INVALIDCALL. I find no any solution after several days search and debug.give me some clue or any other suggestion (like code style etc..)thanks.   
  What is the HRESULT being returned when the API fails?According to the SDK docs, pSrcRect cannot be NULL and you're setting it to zero.I also find it odd that you're specifying a color key and the surface format doesn't contain an alpha channel.