代码如下,编译没问题:
    HRESULT hr;
    hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);     
    IHTMLDocument2   *pDoc   =   NULL; 
    hr = CoCreateInstance(CLSID_HTMLDocument,NULL,CLSCTX_INPROC_SERVER,IID_IHTMLDocument2,(LPVOID *) &pDoc);  
    if   (pDoc)  
    {  
        IPersistStreamInit  *pPersist   =   NULL;   
        hr = pDoc->QueryInterface(IID_IPersistStreamInit,(LPVOID *) &pPersist);   
        if   (pPersist)  
        {  
            IMarkupServices   *pMS   =   NULL;  
       
            pPersist->InitNew();
            pPersist->Release();  
   
            hr = pDoc->QueryInterface(IID_IMarkupServices,(LPVOID *)   &pMS);   
            if (pMS)
            { 
                // Do works.
            }  
        }  
   
        pDoc->Release();  
    }  
   
    CoUninitialize();  如上代码,pDoc->QueryInterface(IID_IMarkupServices, (LPVOID *) &pMS)总是返回E_NOINTERFACE。
开发环境:
Windows XP SP3, IE7, VS2005 Professional.

解决方案 »

  1.   

    估计是IHTMLDocument2*需要一些额外的操作 比如open之类的 打开一个有效的url或者文档
    我只从IWebBrowser2* navigate一个url再获得的IHTMLDocument2*这么用过 注意下msdn这段话 可能问题在这里:
    Typically, every window object has a corresponding document object that you can get by calling the QueryInterface method with the IID_IHTMLDocument or IID_IHTMLDocument2 interface identifiers. Windows that contain HTML documents always have valid document objects; windows that contain documents in other formats might not have valid document objects.In general, before you attempt to get the document object for a window that is not the current window, make sure that the source file associated with that window is an HTML document file or a file that can be represented as an HTML document, for example, a text file.
      

  2.   

    因为在我的程序中并不使用WebBrowser,而是需要针对一段HTML文本字符串进行处理,比如获得其中的image路径等。另外,我搜索了注册表,并没有发现IMarkupServices。
    请大家帮助,谢谢。