PRB: ShowHTMLDialog Returns E_NOINTERFACE (0x80004002)ID: Q183413
|
ShowHTMLDialog returns an HRESULT of 0x80004002 - E_NOINTERFACE.
ShowHTMLDialog must be called from a thread that is a member of an apartment initialized by CoInitialize.
Change CoInitializeEx(NULL, COINIT_MULTITHREADED) calls to CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) or move the ShowHTMLDialog call to another thread that is apartment threaded.
This behavior is by design.
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;
}
Additional query words:
Keywords : kbcode kbIE500
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 30, 1999