How do I use Marshal.QueryInterface?
<p>I am trying to work with some embedded objects in Word documents. An earlier poster told me that this is not straight forward. Here is an excerpt of the linked answer:</p>

<blockquote>
  <p>"As I mentioned earlier, utilizing the
  embedded object's programming model to
  perform the save is something of a
  shortcut.  There is a more involved
  solution that will work with any
  embedded object.  In order for the
  object to be embedded in the first
  place, it must support one of the COM
  IPersist interfaces (i.e
  IPersistStorage, IPersistStreamInit,
  IPersistFile, etc).  Therefore, an
  embedded object can always be
  extracted by calling
  Marshal.QueryInterface on the
  OLEFormat.Object (to determine the
  appropriate persistance interface),
  casting accordingly and then calling
  the appropriate method.  Depending on
  which persistence interface you use,
  you may need to call some additional
  methods to expose the appropriate
  storage over the top of a file.  Also,
  depending on the type of embedded
  object, you may still need to activate
  the object prior to being able to
  successfully QueryInterface for the
  persistance interfaces."</p>
</blockquote>

<p>So I am interested in exposing which interface the object is implementing. The closest I could find is <a href="http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.interop/2007-07/msg00054.html" rel="nofollow">here</a>. The code so far is below and any help with the Marshal.QueryInterface is greatly appreciated.</p>

<pre><code>// Opening the word document
object missing = Type.Missing;
this.document = wordApp.Documents.Open(
                ref fn, ref confirmConversions, ref readOnly, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing);

foreach (Microsoft.Office.Interop.Word.InlineShape inlineShape in this.document.InlineShapes)
            {
                if (inlineShape.OLEFormat.ProgID != null)
                {
                    switch (inlineShape.OLEFormat.ProgID)
                    {
                        // This is a pdf file
                        case "AcroExch.Document.7":
                            //Marshal.QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
                            break;
                        default:
                            break;
                    }
                }
            }
</code></pre>
