Have you taken a look at the DirectXTK library? I believe this method is already implemented for you, or at least it can provide you with a reference implementation to start from...
This is exactly what I need from the DirectXTK library:
HRESULT SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _In_z_ LPCWSTR fileName );
however this library need Windows 8 SDK(that needs w8, and I don't have). It looks like only for this method I only missing <DirectXMath.h> and <wrl.h>, any suggestion ?
edit: I currently use DirectX SDK (June 2010)