I assume you already have the camera position, which I'll call m_cameraPosition.
this returns the mouse direction in 3D:
POINT mp = getMousePosition();
D3DXVECTOR3 v;
v.x = ( ( ( 2.0f * mp.x ) / m_width ) - 1 ) / m_perspectiveProjection._11;
v.y = -( ( ( 2.0f * mp.y ) / m_height ) - 1 ) / m_perspectiveProjection._22;
v.z = 1.0f;
D3DXMATRIX m;
D3DXVECTOR3 rayDir;
D3DXMatrixInverse( &m, NULL, &getCameraMatrix() );
// Transform the screen space pick ray into 3D space
rayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
rayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
rayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
return rayDir;
.
getCameraMatrix() returns the camera view matrix
m_perspectiveProjection is the projection matrix
m_width and m_height are the size of the screen
getMousePosition() returns the client mouse position
so the final position would be:
rayDir * distance + m_cameraPosition;
change distance as you desire, or calculate it if you need that z = 50