PRB: ShowHTMLDialog Returns E_NOINTERFACE (0x80004002)

ID: Q183413


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 5.0


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;
} 

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Jason Strayer, Microsoft Corporation

Additional query words:

Keywords : kbcode kbIE500
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: November 17, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.