Help and Support

Article ID: 183413 - Last Review: November 19, 1999 - Revision: 1.0

PRB: ShowHTMLDialog Returns E_NOINTERFACE (0x80004002)

This article was previously published under Q183413
Expand all | Collapse all

SYMPTOMS

ShowHTMLDialog returns an HRESULT of 0x80004002 - E_NOINTERFACE.

CAUSE

ShowHTMLDialog must be called from a thread that is a member of an apartment initialized by CoInitialize.

RESOLUTION

Change CoInitializeEx(NULL, COINIT_MULTITHREADED) calls to CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) or move the ShowHTMLDialog call to another thread that is apartment threaded.

STATUS

This behavior is by design.

MORE INFORMATION

The following code snippet demonstrates the problem:
#include <windows.h>
#include <mshtmhst.h>
#include <urlmon.h>
#include <tchar.h>
#include <comdef.h>
#include <objbase.h>
#pragma comment(lib, "urlmon.lib")

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                     LPSTR lpCmdLine, int nCmdShow)
{
    HRESULT   hr;
    IMonikerPtr pmk;
    OLECHAR* pchHTML = L"http://www.microsoft.com";
    SHOWHTMLDIALOGFN* pfnShowHTMLDialog = NULL;
    HINSTANCE hinstMSHTML = NULL;

    // ***
    // *** The following should be
    // *** CoInitialize(NULL, COINIT_APARTMENTTHREADED);
    // ***
    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    hinstMSHTML = LoadLibrary(TEXT("MSHTML.DLL"));

    if (NULL != hinstMSHTML)
    {
       pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)
                   GetProcAddress(hinstMSHTML, TEXT("ShowHTMLDialog"));
    }

    if (NULL != pfnShowHTMLDialog)
       hr = CreateURLMoniker(NULL, pchHTML, &pmk);

    if (SUCCEEDED(hr))
    {
       hr = pfnShowHTMLDialog(NULL,       // HWND        hwndParent,
                              pmk,        // IMoniker *  pMk,
                              NULL,       // TCHAR *     pchURL,
                              NULL,       // VARIANT *   pvarArgIn,
                              NULL        // VARIANT *   pvarArgOut,
                              );
    }

    if (hinstMSHTML)
        FreeLibrary(hinstMSHTML);

    CoUninitialize();

    return 0;
}
				


APPLIES TO
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2
Keywords: 
kbcode kbprb KB183413
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Article Translations

 

Related Support Centers