Use Marshal.GetLastWin32Error instead of GetLastError.

Also removes magic number 1171 and replaces with constant.