title: When return E_POINTER and when E_INVALIDARG?
body: <p>COM interfaces methods can return various <code>HRESULT</code> values to signal invalid argument values passed. When do I return <code>E_POINTER</code> and when <code>E_INVALIDARG</code>?</p>
  
  <p>As I understand if a method receives an index in an encapsulated collection and it is out of bounds that is <code>E_INVALIDARG</code>. If a method receives an <code>Interface**</code> pointer where it is meant to store a pointer to a newly created object that's <code>E_POINTER</code>.</p>
  
  <pre><code>HRESULT CImpl::GetItem( long index; Interface** result )
  {
      if( result == 0 ) {
          return E_POINTER;
      }
      if( index &lt; 0 || index &gt;= internalArray.size() ) {
          return E_INVALIDARG;
      }
      *result = CreateWrapperObject( internalArray[index] );
      return S_OK;
  }
  </code></pre>
  
  <p>But what if it receives a <code>WCHAR*</code> buffer with a file name as an "in" parameter and this <code>WCHAR*</code> is null? Is this <code>E_POINTER</code> or <code>E_INVALIDARG</code>?</p>
  
  <p>Or a method receives a pointer to some struct and is expected to fill the struct through that pointer and this pointer is null - is this <code>E_POINTER</code> or <code>E_INVALIDARG</code>?</p>
  
  <pre><code>HRESULT CImpl::SaveToFile( WCHAR* fileName )
  {
      if( fileName == 0 ) {
         return // what to return here?
      }
      //... do actual work here
  }
  
  HRESULT CImpl::GetAttributes( Attributes* to )
  {
      if( to == 0 ) {
         return // what to return here?
      }
      attributes-&gt;IsCool = getIsCool();
      attributes-&gt;Color = RGB( 0, 255, 0 );
      return S_OK;
  }
  </code></pre>
  
  <p>What are the rules for when to return <code>E_POINTER</code> and when <code>E_INVALIDARG</code> when checking pointer type parameters?</p>