title: defaultvalue and retval parameter ordering in IDL file and C++ header file
body: <p>I'm trying to update an existing COM API to include a new optional output parameter, and have run into an issue with the enforced ordering of parameter types in the IDL file and the associated C++ header file.</p>
  
  <p>Previously I had an IDL file like this (names changed to protect the innocent):</p>
  
  <pre><code>HRESULT CreateSomething(
      [in] BSTR base_uri,
      [in] ISomethingDescription* something_description,
      [out, retval] BSTR* something_uri
  );
  </code></pre>
  
  <p>and the associated C++ header looked like:</p>
  
  <pre><code>HRESULT __stdcall CreateSomething(
      /* [in] */ BSTR study_uri,
      /* [in] */ ISomethingDescription* something_description,
      /* [out, retval] */ BSTR* something_uri
  );
  </code></pre>
  
  <p>This needed to be updated to add an optional output parameter that could provide some clients with extra error reporting information, following an existing pattern against the rest of the in-house SDK.</p>
  
  <p>To do this I was planning to update the IDL file to look like this:</p>
  
  <pre><code>HRESULT CreateSomething(
      [in] BSTR base_uri,
      [in] ISomethingDescription* something_description,
      [out, defaultvalue(0)] ErrorCode* error_code,
      [out, retval] BSTR* something_uri
  );
  </code></pre>
  
  <p>Where ErrorCode is an enum defined in a separate IDL file. This follows the guidance I have seen online about how parameters with defaultvalue and retval attributes should be ordered. However, when I then try to upate the C++ header file, I run into the issue that the default parameter is not at the end of the parameter list, i.e.</p>
  
  <pre><code>HRESULT __stdcall CreateSomething(
      /* [in] */ BSTR study_uri,
      /* [in] */ ISomethingDescription* something_description,
      /* [out, defaultvalue(0)] */ ErrorCode* error_code = 0,   // this is clearly wrong
      /* [out, retval] */ BSTR* something_uri
  );
  </code></pre>
  
  <p>The documentation I have seen on MSDN seems to indicate that you can use parameters with defaultvalue and retval attributes within the same function definition, and I have seen some examples of IDL files that contain such definitions, but I cannot work out how it is possible to write the equivalent C++ definition.</p>
  
  <p>Some clients (and our own test code) use the MIDL generated header files directly, so if I omit the default values from the original C++ header file, the generated function in the MIDL generated file does not contain a default value entry, i.e. it looks like this:</p>
  
  <pre><code>virtual HRESULT STDMETHODCALLTYPE CreateSomething( 
              /* [in] */ BSTR base_uri,
              /* [in] */ ISomethingDescription *something_description,
              /* [defaultvalue][out] */ ErrorCode *error_code,
              /* [retval][out] */ BSTR *something_uri) = 0;
  </code></pre>
  
  <p>Similar functions in our SDK include the default values in the IDL file and the C++ header - not to say that that whole approach isn't questionable.</p>
  
  <p>Any help/advice on this would be greatly appreciated.</p>